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

Function parseOptionsExpression

lib/test/angular/1.7.0/angular.js:31302–31456  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

31300var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) {
31301
31302 function parseOptionsExpression(optionsExp, selectElement, scope) {
31303
31304 var match = optionsExp.match(NG_OPTIONS_REGEXP);
31305 if (!(match)) {
31306 throw ngOptionsMinErr('iexp',
31307 'Expected expression in form of ' +
31308 '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' +
31309 ' but got \'{0}\'. Element: {1}',
31310 optionsExp, startingTag(selectElement));
31311 }
31312
31313 // Extract the parts from the ngOptions expression
31314
31315 // The variable name for the value of the item in the collection
31316 var valueName = match[5] || match[7];
31317 // The variable name for the key of the item in the collection
31318 var keyName = match[6];
31319
31320 // An expression that generates the viewValue for an option if there is a label expression
31321 var selectAs = / as /.test(match[0]) && match[1];
31322 // An expression that is used to track the id of each object in the options collection
31323 var trackBy = match[9];
31324 // An expression that generates the viewValue for an option if there is no label expression
31325 var valueFn = $parse(match[2] ? match[1] : valueName);
31326 var selectAsFn = selectAs && $parse(selectAs);
31327 var viewValueFn = selectAsFn || valueFn;
31328 var trackByFn = trackBy && $parse(trackBy);
31329
31330 // Get the value by which we are going to track the option
31331 // if we have a trackFn then use that (passing scope and locals)
31332 // otherwise just hash the given viewValue
31333 var getTrackByValueFn = trackBy ?
31334 function(value, locals) { return trackByFn(scope, locals); } :
31335 function getHashOfValue(value) { return hashKey(value); };
31336 var getTrackByValue = function(value, key) {
31337 return getTrackByValueFn(value, getLocals(value, key));
31338 };
31339
31340 var displayFn = $parse(match[2] || match[1]);
31341 var groupByFn = $parse(match[3] || '');
31342 var disableWhenFn = $parse(match[4] || '');
31343 var valuesFn = $parse(match[8]);
31344
31345 var locals = {};
31346 var getLocals = keyName ? function(value, key) {
31347 locals[keyName] = key;
31348 locals[valueName] = value;
31349 return locals;
31350 } : function(value) {
31351 locals[valueName] = value;
31352 return locals;
31353 };
31354
31355
31356 function Option(selectValue, viewValue, label, group, disabled) {
31357 this.selectValue = selectValue;
31358 this.viewValue = viewValue;
31359 this.label = label;

Callers 1

ngOptionsPostLinkFunction · 0.70

Calls 6

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

Tested by

no test coverage detected