MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / setupAsOptions

Function setupAsOptions

code/songhop/www/lib/angular/angular.js:25565–25925  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

25563 }
25564
25565 function setupAsOptions(scope, selectElement, ctrl) {
25566 var match;
25567
25568 if (!(match = optionsExp.match(NG_OPTIONS_REGEXP))) {
25569 throw ngOptionsMinErr('iexp',
25570 "Expected expression in form of " +
25571 "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
25572 " but got '{0}'. Element: {1}",
25573 optionsExp, startingTag(selectElement));
25574 }
25575
25576 var displayFn = $parse(match[2] || match[1]),
25577 valueName = match[4] || match[6],
25578 selectAs = / as /.test(match[0]) && match[1],
25579 selectAsFn = selectAs ? $parse(selectAs) : null,
25580 keyName = match[5],
25581 groupByFn = $parse(match[3] || ''),
25582 valueFn = $parse(match[2] ? match[1] : valueName),
25583 valuesFn = $parse(match[7]),
25584 track = match[8],
25585 trackFn = track ? $parse(match[8]) : null,
25586 trackKeysCache = {},
25587 // This is an array of array of existing option groups in DOM.
25588 // We try to reuse these if possible
25589 // - optionGroupsCache[0] is the options with no option group
25590 // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
25591 optionGroupsCache = [[{element: selectElement, label:''}]],
25592 //re-usable object to represent option's locals
25593 locals = {};
25594
25595 if (nullOption) {
25596 // compile the element since there might be bindings in it
25597 $compile(nullOption)(scope);
25598
25599 // remove the class, which is added automatically because we recompile the element and it
25600 // becomes the compilation root
25601 nullOption.removeClass('ng-scope');
25602
25603 // we need to remove it before calling selectElement.empty() because otherwise IE will
25604 // remove the label from the element. wtf?
25605 nullOption.remove();
25606 }
25607
25608 // clear contents, we'll add what's needed based on the model
25609 selectElement.empty();
25610
25611 selectElement.on('change', selectionChanged);
25612
25613 ctrl.$render = render;
25614
25615 scope.$watchCollection(valuesFn, scheduleRendering);
25616 scope.$watchCollection(getLabels, scheduleRendering);
25617
25618 if (multiple) {
25619 scope.$watchCollection(function() { return ctrl.$modelValue; }, scheduleRendering);
25620 }
25621
25622 // ------------------------------------------------------------------ //

Callers 1

angular.jsFile · 0.70

Calls 1

startingTagFunction · 0.70

Tested by

no test coverage detected