(optionsExp, selectElement, scope)
| 32340 | var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, $document, $parse) { |
| 32341 | |
| 32342 | function parseOptionsExpression(optionsExp, selectElement, scope) { |
| 32343 | |
| 32344 | var match = optionsExp.match(NG_OPTIONS_REGEXP); |
| 32345 | if (!(match)) { |
| 32346 | throw ngOptionsMinErr('iexp', |
| 32347 | 'Expected expression in form of ' + |
| 32348 | '\'_select_ (as _label_)? for (_key_,)?_value_ in _collection_\'' + |
| 32349 | ' but got \'{0}\'. Element: {1}', |
| 32350 | optionsExp, startingTag(selectElement)); |
| 32351 | } |
| 32352 | |
| 32353 | // Extract the parts from the ngOptions expression |
| 32354 | |
| 32355 | // The variable name for the value of the item in the collection |
| 32356 | var valueName = match[5] || match[7]; |
| 32357 | // The variable name for the key of the item in the collection |
| 32358 | var keyName = match[6]; |
| 32359 | |
| 32360 | // An expression that generates the viewValue for an option if there is a label expression |
| 32361 | var selectAs = / as /.test(match[0]) && match[1]; |
| 32362 | // An expression that is used to track the id of each object in the options collection |
| 32363 | var trackBy = match[9]; |
| 32364 | // An expression that generates the viewValue for an option if there is no label expression |
| 32365 | var valueFn = $parse(match[2] ? match[1] : valueName); |
| 32366 | var selectAsFn = selectAs && $parse(selectAs); |
| 32367 | var viewValueFn = selectAsFn || valueFn; |
| 32368 | var trackByFn = trackBy && $parse(trackBy); |
| 32369 | |
| 32370 | // Get the value by which we are going to track the option |
| 32371 | // if we have a trackFn then use that (passing scope and locals) |
| 32372 | // otherwise just hash the given viewValue |
| 32373 | var getTrackByValueFn = trackBy ? |
| 32374 | function(value, locals) { return trackByFn(scope, locals); } : |
| 32375 | function getHashOfValue(value) { return hashKey(value); }; |
| 32376 | var getTrackByValue = function(value, key) { |
| 32377 | return getTrackByValueFn(value, getLocals(value, key)); |
| 32378 | }; |
| 32379 | |
| 32380 | var displayFn = $parse(match[2] || match[1]); |
| 32381 | var groupByFn = $parse(match[3] || ''); |
| 32382 | var disableWhenFn = $parse(match[4] || ''); |
| 32383 | var valuesFn = $parse(match[8]); |
| 32384 | |
| 32385 | var locals = {}; |
| 32386 | var getLocals = keyName ? function(value, key) { |
| 32387 | locals[keyName] = key; |
| 32388 | locals[valueName] = value; |
| 32389 | return locals; |
| 32390 | } : function(value) { |
| 32391 | locals[valueName] = value; |
| 32392 | return locals; |
| 32393 | }; |
| 32394 | |
| 32395 | |
| 32396 | function Option(selectValue, viewValue, label, group, disabled) { |
| 32397 | this.selectValue = selectValue; |
| 32398 | this.viewValue = viewValue; |
| 32399 | this.label = label; |
no test coverage detected