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

Function parseOptionsExpression

test/angular/1.5/angular.js:29358–29512  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

29356var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) {
29357
29358 function parseOptionsExpression(optionsExp, selectElement, scope) {
29359
29360 var match = optionsExp.match(NG_OPTIONS_REGEXP);
29361 if (!(match)) {
29362 throw ngOptionsMinErr('iexp',
29363 'Expected expression in form of ' +
29364 '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' +
29365 ' but got \'{0}\'. Element: {1}',
29366 optionsExp, startingTag(selectElement));
29367 }
29368
29369 // Extract the parts from the ngOptions expression
29370
29371 // The variable name for the value of the item in the collection
29372 var valueName = match[5] || match[7];
29373 // The variable name for the key of the item in the collection
29374 var keyName = match[6];
29375
29376 // An expression that generates the viewValue for an option if there is a label expression
29377 var selectAs = / as /.test(match[0]) && match[1];
29378 // An expression that is used to track the id of each object in the options collection
29379 var trackBy = match[9];
29380 // An expression that generates the viewValue for an option if there is no label expression
29381 var valueFn = $parse(match[2] ? match[1] : valueName);
29382 var selectAsFn = selectAs && $parse(selectAs);
29383 var viewValueFn = selectAsFn || valueFn;
29384 var trackByFn = trackBy && $parse(trackBy);
29385
29386 // Get the value by which we are going to track the option
29387 // if we have a trackFn then use that (passing scope and locals)
29388 // otherwise just hash the given viewValue
29389 var getTrackByValueFn = trackBy ?
29390 function(value, locals) { return trackByFn(scope, locals); } :
29391 function getHashOfValue(value) { return hashKey(value); };
29392 var getTrackByValue = function(value, key) {
29393 return getTrackByValueFn(value, getLocals(value, key));
29394 };
29395
29396 var displayFn = $parse(match[2] || match[1]);
29397 var groupByFn = $parse(match[3] || '');
29398 var disableWhenFn = $parse(match[4] || '');
29399 var valuesFn = $parse(match[8]);
29400
29401 var locals = {};
29402 var getLocals = keyName ? function(value, key) {
29403 locals[keyName] = key;
29404 locals[valueName] = value;
29405 return locals;
29406 } : function(value) {
29407 locals[valueName] = value;
29408 return locals;
29409 };
29410
29411
29412 function Option(selectValue, viewValue, label, group, disabled) {
29413 this.selectValue = selectValue;
29414 this.viewValue = viewValue;
29415 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