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

Function parseOptionsExpression

test/angular/1.6/angular.js:31079–31233  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

31077var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) {
31078
31079 function parseOptionsExpression(optionsExp, selectElement, scope) {
31080
31081 var match = optionsExp.match(NG_OPTIONS_REGEXP);
31082 if (!(match)) {
31083 throw ngOptionsMinErr('iexp',
31084 'Expected expression in form of ' +
31085 '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' +
31086 ' but got \'{0}\'. Element: {1}',
31087 optionsExp, startingTag(selectElement));
31088 }
31089
31090 // Extract the parts from the ngOptions expression
31091
31092 // The variable name for the value of the item in the collection
31093 var valueName = match[5] || match[7];
31094 // The variable name for the key of the item in the collection
31095 var keyName = match[6];
31096
31097 // An expression that generates the viewValue for an option if there is a label expression
31098 var selectAs = / as /.test(match[0]) && match[1];
31099 // An expression that is used to track the id of each object in the options collection
31100 var trackBy = match[9];
31101 // An expression that generates the viewValue for an option if there is no label expression
31102 var valueFn = $parse(match[2] ? match[1] : valueName);
31103 var selectAsFn = selectAs && $parse(selectAs);
31104 var viewValueFn = selectAsFn || valueFn;
31105 var trackByFn = trackBy && $parse(trackBy);
31106
31107 // Get the value by which we are going to track the option
31108 // if we have a trackFn then use that (passing scope and locals)
31109 // otherwise just hash the given viewValue
31110 var getTrackByValueFn = trackBy ?
31111 function(value, locals) { return trackByFn(scope, locals); } :
31112 function getHashOfValue(value) { return hashKey(value); };
31113 var getTrackByValue = function(value, key) {
31114 return getTrackByValueFn(value, getLocals(value, key));
31115 };
31116
31117 var displayFn = $parse(match[2] || match[1]);
31118 var groupByFn = $parse(match[3] || '');
31119 var disableWhenFn = $parse(match[4] || '');
31120 var valuesFn = $parse(match[8]);
31121
31122 var locals = {};
31123 var getLocals = keyName ? function(value, key) {
31124 locals[keyName] = key;
31125 locals[valueName] = value;
31126 return locals;
31127 } : function(value) {
31128 locals[valueName] = value;
31129 return locals;
31130 };
31131
31132
31133 function Option(selectValue, viewValue, label, group, disabled) {
31134 this.selectValue = selectValue;
31135 this.viewValue = viewValue;
31136 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