MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / parseOptionsExpression

Function parseOptionsExpression

lib/test/angular/1.5.0/angular.js:27299–27453  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

27297var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
27298
27299 function parseOptionsExpression(optionsExp, selectElement, scope) {
27300
27301 var match = optionsExp.match(NG_OPTIONS_REGEXP);
27302 if (!(match)) {
27303 throw ngOptionsMinErr('iexp',
27304 "Expected expression in form of " +
27305 "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
27306 " but got '{0}'. Element: {1}",
27307 optionsExp, startingTag(selectElement));
27308 }
27309
27310 // Extract the parts from the ngOptions expression
27311
27312 // The variable name for the value of the item in the collection
27313 var valueName = match[5] || match[7];
27314 // The variable name for the key of the item in the collection
27315 var keyName = match[6];
27316
27317 // An expression that generates the viewValue for an option if there is a label expression
27318 var selectAs = / as /.test(match[0]) && match[1];
27319 // An expression that is used to track the id of each object in the options collection
27320 var trackBy = match[9];
27321 // An expression that generates the viewValue for an option if there is no label expression
27322 var valueFn = $parse(match[2] ? match[1] : valueName);
27323 var selectAsFn = selectAs && $parse(selectAs);
27324 var viewValueFn = selectAsFn || valueFn;
27325 var trackByFn = trackBy && $parse(trackBy);
27326
27327 // Get the value by which we are going to track the option
27328 // if we have a trackFn then use that (passing scope and locals)
27329 // otherwise just hash the given viewValue
27330 var getTrackByValueFn = trackBy ?
27331 function(value, locals) { return trackByFn(scope, locals); } :
27332 function getHashOfValue(value) { return hashKey(value); };
27333 var getTrackByValue = function(value, key) {
27334 return getTrackByValueFn(value, getLocals(value, key));
27335 };
27336
27337 var displayFn = $parse(match[2] || match[1]);
27338 var groupByFn = $parse(match[3] || '');
27339 var disableWhenFn = $parse(match[4] || '');
27340 var valuesFn = $parse(match[8]);
27341
27342 var locals = {};
27343 var getLocals = keyName ? function(value, key) {
27344 locals[keyName] = key;
27345 locals[valueName] = value;
27346 return locals;
27347 } : function(value) {
27348 locals[valueName] = value;
27349 return locals;
27350 };
27351
27352
27353 function Option(selectValue, viewValue, label, group, disabled) {
27354 this.selectValue = selectValue;
27355 this.viewValue = viewValue;
27356 this.label = label;

Callers 1

ngOptionsPostLinkFunction · 0.70

Calls 5

startingTagFunction · 0.70
$parseFunction · 0.70
hashKeyFunction · 0.70
getOptionValuesKeysFunction · 0.70
getTrackByValueFunction · 0.70

Tested by

no test coverage detected