(optionsExp, selectElement, scope)
| 26835 | var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) { |
| 26836 | |
| 26837 | function parseOptionsExpression(optionsExp, selectElement, scope) { |
| 26838 | |
| 26839 | var match = optionsExp.match(NG_OPTIONS_REGEXP); |
| 26840 | if (!(match)) { |
| 26841 | throw ngOptionsMinErr('iexp', |
| 26842 | "Expected expression in form of " + |
| 26843 | "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" + |
| 26844 | " but got '{0}'. Element: {1}", |
| 26845 | optionsExp, startingTag(selectElement)); |
| 26846 | } |
| 26847 | |
| 26848 | // Extract the parts from the ngOptions expression |
| 26849 | |
| 26850 | // The variable name for the value of the item in the collection |
| 26851 | var valueName = match[5] || match[7]; |
| 26852 | // The variable name for the key of the item in the collection |
| 26853 | var keyName = match[6]; |
| 26854 | |
| 26855 | // An expression that generates the viewValue for an option if there is a label expression |
| 26856 | var selectAs = / as /.test(match[0]) && match[1]; |
| 26857 | // An expression that is used to track the id of each object in the options collection |
| 26858 | var trackBy = match[9]; |
| 26859 | // An expression that generates the viewValue for an option if there is no label expression |
| 26860 | var valueFn = $parse(match[2] ? match[1] : valueName); |
| 26861 | var selectAsFn = selectAs && $parse(selectAs); |
| 26862 | var viewValueFn = selectAsFn || valueFn; |
| 26863 | var trackByFn = trackBy && $parse(trackBy); |
| 26864 | |
| 26865 | // Get the value by which we are going to track the option |
| 26866 | // if we have a trackFn then use that (passing scope and locals) |
| 26867 | // otherwise just hash the given viewValue |
| 26868 | var getTrackByValueFn = trackBy ? |
| 26869 | function(value, locals) { return trackByFn(scope, locals); } : |
| 26870 | function getHashOfValue(value) { return hashKey(value); }; |
| 26871 | var getTrackByValue = function(value, key) { |
| 26872 | return getTrackByValueFn(value, getLocals(value, key)); |
| 26873 | }; |
| 26874 | |
| 26875 | var displayFn = $parse(match[2] || match[1]); |
| 26876 | var groupByFn = $parse(match[3] || ''); |
| 26877 | var disableWhenFn = $parse(match[4] || ''); |
| 26878 | var valuesFn = $parse(match[8]); |
| 26879 | |
| 26880 | var locals = {}; |
| 26881 | var getLocals = keyName ? function(value, key) { |
| 26882 | locals[keyName] = key; |
| 26883 | locals[valueName] = value; |
| 26884 | return locals; |
| 26885 | } : function(value) { |
| 26886 | locals[valueName] = value; |
| 26887 | return locals; |
| 26888 | }; |
| 26889 | |
| 26890 | |
| 26891 | function Option(selectValue, viewValue, label, group, disabled) { |
| 26892 | this.selectValue = selectValue; |
| 26893 | this.viewValue = viewValue; |
| 26894 | this.label = label; |
no test coverage detected