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

Function parseOptionsExpression

lib/test/angular/1.6.7/angular.js:30518–30672  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

30516var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) {
30517
30518 function parseOptionsExpression(optionsExp, selectElement, scope) {
30519
30520 var match = optionsExp.match(NG_OPTIONS_REGEXP);
30521 if (!(match)) {
30522 throw ngOptionsMinErr('iexp',
30523 'Expected expression in form of ' +
30524 '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' +
30525 ' but got \'{0}\'. Element: {1}',
30526 optionsExp, startingTag(selectElement));
30527 }
30528
30529 // Extract the parts from the ngOptions expression
30530
30531 // The variable name for the value of the item in the collection
30532 var valueName = match[5] || match[7];
30533 // The variable name for the key of the item in the collection
30534 var keyName = match[6];
30535
30536 // An expression that generates the viewValue for an option if there is a label expression
30537 var selectAs = / as /.test(match[0]) && match[1];
30538 // An expression that is used to track the id of each object in the options collection
30539 var trackBy = match[9];
30540 // An expression that generates the viewValue for an option if there is no label expression
30541 var valueFn = $parse(match[2] ? match[1] : valueName);
30542 var selectAsFn = selectAs && $parse(selectAs);
30543 var viewValueFn = selectAsFn || valueFn;
30544 var trackByFn = trackBy && $parse(trackBy);
30545
30546 // Get the value by which we are going to track the option
30547 // if we have a trackFn then use that (passing scope and locals)
30548 // otherwise just hash the given viewValue
30549 var getTrackByValueFn = trackBy ?
30550 function(value, locals) { return trackByFn(scope, locals); } :
30551 function getHashOfValue(value) { return hashKey(value); };
30552 var getTrackByValue = function(value, key) {
30553 return getTrackByValueFn(value, getLocals(value, key));
30554 };
30555
30556 var displayFn = $parse(match[2] || match[1]);
30557 var groupByFn = $parse(match[3] || '');
30558 var disableWhenFn = $parse(match[4] || '');
30559 var valuesFn = $parse(match[8]);
30560
30561 var locals = {};
30562 var getLocals = keyName ? function(value, key) {
30563 locals[keyName] = key;
30564 locals[valueName] = value;
30565 return locals;
30566 } : function(value) {
30567 locals[valueName] = value;
30568 return locals;
30569 };
30570
30571
30572 function Option(selectValue, viewValue, label, group, disabled) {
30573 this.selectValue = selectValue;
30574 this.viewValue = viewValue;
30575 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