MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / setupAsOptions

Function setupAsOptions

test/fixtures/foo.js:21584–21877  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

21582 }
21583
21584 function setupAsOptions(scope, selectElement, ctrl) {
21585 var match;
21586
21587 if (!(match = optionsExp.match(NG_OPTIONS_REGEXP))) {
21588 throw ngOptionsMinErr('iexp',
21589 "Expected expression in form of " +
21590 "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
21591 " but got '{0}'. Element: {1}",
21592 optionsExp, startingTag(selectElement));
21593 }
21594
21595 var displayFn = $parse(match[2] || match[1]),
21596 valueName = match[4] || match[6],
21597 keyName = match[5],
21598 groupByFn = $parse(match[3] || ''),
21599 valueFn = $parse(match[2] ? match[1] : valueName),
21600 valuesFn = $parse(match[7]),
21601 track = match[8],
21602 trackFn = track ? $parse(match[8]) : null,
21603 // This is an array of array of existing option groups in DOM.
21604 // We try to reuse these if possible
21605 // - optionGroupsCache[0] is the options with no option group
21606 // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
21607 optionGroupsCache = [[{element: selectElement, label:''}]];
21608
21609 if (nullOption) {
21610 // compile the element since there might be bindings in it
21611 $compile(nullOption)(scope);
21612
21613 // remove the class, which is added automatically because we recompile the element and it
21614 // becomes the compilation root
21615 nullOption.removeClass('ng-scope');
21616
21617 // we need to remove it before calling selectElement.empty() because otherwise IE will
21618 // remove the label from the element. wtf?
21619 nullOption.remove();
21620 }
21621
21622 // clear contents, we'll add what's needed based on the model
21623 selectElement.empty();
21624
21625 selectElement.on('change', function() {
21626 scope.$apply(function() {
21627 var optionGroup,
21628 collection = valuesFn(scope) || [],
21629 locals = {},
21630 key, value, optionElement, index, groupIndex, length, groupLength, trackIndex;
21631
21632 if (multiple) {
21633 value = [];
21634 for (groupIndex = 0, groupLength = optionGroupsCache.length;
21635 groupIndex < groupLength;
21636 groupIndex++) {
21637 // list of options for that group. (first item has the parent)
21638 optionGroup = optionGroupsCache[groupIndex];
21639
21640 for(index = 1, length = optionGroup.length; index < length; index++) {
21641 if ((optionElement = optionGroup[index].element)[0].selected) {

Callers 1

foo.jsFile · 0.85

Calls 3

startingTagFunction · 0.85
valueFnFunction · 0.85
renderFunction · 0.85

Tested by

no test coverage detected