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

Function parseOptionsExpression

test/angular/1.7/angular.js:32277–32431  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

32275var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) {
32276
32277 function parseOptionsExpression(optionsExp, selectElement, scope) {
32278
32279 var match = optionsExp.match(NG_OPTIONS_REGEXP);
32280 if (!(match)) {
32281 throw ngOptionsMinErr('iexp',
32282 'Expected expression in form of ' +
32283 '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' +
32284 ' but got \'{0}\'. Element: {1}',
32285 optionsExp, startingTag(selectElement));
32286 }
32287
32288 // Extract the parts from the ngOptions expression
32289
32290 // The variable name for the value of the item in the collection
32291 var valueName = match[5] || match[7];
32292 // The variable name for the key of the item in the collection
32293 var keyName = match[6];
32294
32295 // An expression that generates the viewValue for an option if there is a label expression
32296 var selectAs = / as /.test(match[0]) && match[1];
32297 // An expression that is used to track the id of each object in the options collection
32298 var trackBy = match[9];
32299 // An expression that generates the viewValue for an option if there is no label expression
32300 var valueFn = $parse(match[2] ? match[1] : valueName);
32301 var selectAsFn = selectAs && $parse(selectAs);
32302 var viewValueFn = selectAsFn || valueFn;
32303 var trackByFn = trackBy && $parse(trackBy);
32304
32305 // Get the value by which we are going to track the option
32306 // if we have a trackFn then use that (passing scope and locals)
32307 // otherwise just hash the given viewValue
32308 var getTrackByValueFn = trackBy ?
32309 function(value, locals) { return trackByFn(scope, locals); } :
32310 function getHashOfValue(value) { return hashKey(value); };
32311 var getTrackByValue = function(value, key) {
32312 return getTrackByValueFn(value, getLocals(value, key));
32313 };
32314
32315 var displayFn = $parse(match[2] || match[1]);
32316 var groupByFn = $parse(match[3] || '');
32317 var disableWhenFn = $parse(match[4] || '');
32318 var valuesFn = $parse(match[8]);
32319
32320 var locals = {};
32321 var getLocals = keyName ? function(value, key) {
32322 locals[keyName] = key;
32323 locals[valueName] = value;
32324 return locals;
32325 } : function(value) {
32326 locals[valueName] = value;
32327 return locals;
32328 };
32329
32330
32331 function Option(selectValue, viewValue, label, group, disabled) {
32332 this.selectValue = selectValue;
32333 this.viewValue = viewValue;
32334 this.label = label;

Callers 1

ngOptionsPostLinkFunction · 0.70

Calls 8

getLocalsFunction · 0.85
matchMethod · 0.80
startingTagFunction · 0.70
$parseFunction · 0.70
hashKeyFunction · 0.70
getOptionValuesKeysFunction · 0.70
getTrackByValueFunction · 0.70
copyFunction · 0.70

Tested by

no test coverage detected