(scope, selectElement, ctrl)
| 21807 | } |
| 21808 | |
| 21809 | function setupAsOptions(scope, selectElement, ctrl) { |
| 21810 | var match; |
| 21811 | |
| 21812 | if (!(match = optionsExp.match(NG_OPTIONS_REGEXP))) { |
| 21813 | throw ngOptionsMinErr('iexp', |
| 21814 | "Expected expression in form of " + |
| 21815 | "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" + |
| 21816 | " but got '{0}'. Element: {1}", |
| 21817 | optionsExp, startingTag(selectElement)); |
| 21818 | } |
| 21819 | |
| 21820 | var displayFn = $parse(match[2] || match[1]), |
| 21821 | valueName = match[4] || match[6], |
| 21822 | keyName = match[5], |
| 21823 | groupByFn = $parse(match[3] || ''), |
| 21824 | valueFn = $parse(match[2] ? match[1] : valueName), |
| 21825 | valuesFn = $parse(match[7]), |
| 21826 | track = match[8], |
| 21827 | trackFn = track ? $parse(match[8]) : null, |
| 21828 | // This is an array of array of existing option groups in DOM. |
| 21829 | // We try to reuse these if possible |
| 21830 | // - optionGroupsCache[0] is the options with no option group |
| 21831 | // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element |
| 21832 | optionGroupsCache = [[{element: selectElement, label:''}]]; |
| 21833 | |
| 21834 | if (nullOption) { |
| 21835 | // compile the element since there might be bindings in it |
| 21836 | $compile(nullOption)(scope); |
| 21837 | |
| 21838 | // remove the class, which is added automatically because we recompile the element and it |
| 21839 | // becomes the compilation root |
| 21840 | nullOption.removeClass('ng-scope'); |
| 21841 | |
| 21842 | // we need to remove it before calling selectElement.empty() because otherwise IE will |
| 21843 | // remove the label from the element. wtf? |
| 21844 | nullOption.remove(); |
| 21845 | } |
| 21846 | |
| 21847 | // clear contents, we'll add what's needed based on the model |
| 21848 | selectElement.empty(); |
| 21849 | |
| 21850 | selectElement.on('change', function() { |
| 21851 | scope.$apply(function() { |
| 21852 | var optionGroup, |
| 21853 | collection = valuesFn(scope) || [], |
| 21854 | locals = {}, |
| 21855 | key, value, optionElement, index, groupIndex, length, groupLength, trackIndex; |
| 21856 | |
| 21857 | if (multiple) { |
| 21858 | value = []; |
| 21859 | for (groupIndex = 0, groupLength = optionGroupsCache.length; |
| 21860 | groupIndex < groupLength; |
| 21861 | groupIndex++) { |
| 21862 | // list of options for that group. (first item has the parent) |
| 21863 | optionGroup = optionGroupsCache[groupIndex]; |
| 21864 | |
| 21865 | for(index = 1, length = optionGroup.length; index < length; index++) { |
| 21866 | if ((optionElement = optionGroup[index].element)[0].selected) { |
no test coverage detected