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

Function parseOptionsExpression

lib/test/angular/1.4.3/angular.js:25954–26108  ·  view source on GitHub ↗
(optionsExp, selectElement, scope)

Source from the content-addressed store, hash-verified

25952var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
25953
25954 function parseOptionsExpression(optionsExp, selectElement, scope) {
25955
25956 var match = optionsExp.match(NG_OPTIONS_REGEXP);
25957 if (!(match)) {
25958 throw ngOptionsMinErr('iexp',
25959 "Expected expression in form of " +
25960 "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
25961 " but got '{0}'. Element: {1}",
25962 optionsExp, startingTag(selectElement));
25963 }
25964
25965 // Extract the parts from the ngOptions expression
25966
25967 // The variable name for the value of the item in the collection
25968 var valueName = match[5] || match[7];
25969 // The variable name for the key of the item in the collection
25970 var keyName = match[6];
25971
25972 // An expression that generates the viewValue for an option if there is a label expression
25973 var selectAs = / as /.test(match[0]) && match[1];
25974 // An expression that is used to track the id of each object in the options collection
25975 var trackBy = match[9];
25976 // An expression that generates the viewValue for an option if there is no label expression
25977 var valueFn = $parse(match[2] ? match[1] : valueName);
25978 var selectAsFn = selectAs && $parse(selectAs);
25979 var viewValueFn = selectAsFn || valueFn;
25980 var trackByFn = trackBy && $parse(trackBy);
25981
25982 // Get the value by which we are going to track the option
25983 // if we have a trackFn then use that (passing scope and locals)
25984 // otherwise just hash the given viewValue
25985 var getTrackByValueFn = trackBy ?
25986 function(value, locals) { return trackByFn(scope, locals); } :
25987 function getHashOfValue(value) { return hashKey(value); };
25988 var getTrackByValue = function(value, key) {
25989 return getTrackByValueFn(value, getLocals(value, key));
25990 };
25991
25992 var displayFn = $parse(match[2] || match[1]);
25993 var groupByFn = $parse(match[3] || '');
25994 var disableWhenFn = $parse(match[4] || '');
25995 var valuesFn = $parse(match[8]);
25996
25997 var locals = {};
25998 var getLocals = keyName ? function(value, key) {
25999 locals[keyName] = key;
26000 locals[valueName] = value;
26001 return locals;
26002 } : function(value) {
26003 locals[valueName] = value;
26004 return locals;
26005 };
26006
26007
26008 function Option(selectValue, viewValue, label, group, disabled) {
26009 this.selectValue = selectValue;
26010 this.viewValue = viewValue;
26011 this.label = label;

Callers 1

angular.jsFile · 0.70

Calls 5

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

Tested by

no test coverage detected