MCPcopy
hub / github.com/angular-ui/ui-router / updateOptions

Function updateOptions

test/angular/1.6/angular.js:31458–31526  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31456 }
31457
31458 function updateOptions() {
31459 var previousValue = options && selectCtrl.readValue();
31460
31461 // We must remove all current options, but cannot simply set innerHTML = null
31462 // since the providedEmptyOption might have an ngIf on it that inserts comments which we
31463 // must preserve.
31464 // Instead, iterate over the current option elements and remove them or their optgroup
31465 // parents
31466 if (options) {
31467
31468 for (var i = options.items.length - 1; i >= 0; i--) {
31469 var option = options.items[i];
31470 if (isDefined(option.group)) {
31471 jqLiteRemove(option.element.parentNode);
31472 } else {
31473 jqLiteRemove(option.element);
31474 }
31475 }
31476 }
31477
31478 options = ngOptions.getOptions();
31479
31480 var groupElementMap = {};
31481
31482 options.items.forEach(function addOption(option) {
31483 var groupElement;
31484
31485 if (isDefined(option.group)) {
31486
31487 // This option is to live in a group
31488 // See if we have already created this group
31489 groupElement = groupElementMap[option.group];
31490
31491 if (!groupElement) {
31492
31493 groupElement = optGroupTemplate.cloneNode(false);
31494 listFragment.appendChild(groupElement);
31495
31496 // Update the label on the group element
31497 // "null" is special cased because of Safari
31498 groupElement.label = option.group === null ? 'null' : option.group;
31499
31500 // Store it for use later
31501 groupElementMap[option.group] = groupElement;
31502 }
31503
31504 addOptionElement(option, groupElement);
31505
31506 } else {
31507
31508 // This option is not in a group
31509 addOptionElement(option, listFragment);
31510 }
31511 });
31512
31513 selectElement[0].appendChild(listFragment);
31514
31515 ngModelCtrl.$render();

Callers

nothing calls this directly

Calls 4

isDefinedFunction · 0.70
jqLiteRemoveFunction · 0.70
addOptionElementFunction · 0.70
equalsFunction · 0.70

Tested by

no test coverage detected