MCPcopy Create free account
hub / github.com/angular-ui/ui-router / setupAsOptions

Function setupAsOptions

test/angular/1.2/angular.js:21809–22120  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

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) {

Callers 1

angular.jsFile · 0.70

Calls 5

matchMethod · 0.80
startingTagFunction · 0.70
valueFnFunction · 0.70
renderFunction · 0.70
$parseFunction · 0.50

Tested by

no test coverage detected