()
| 29762 | } |
| 29763 | |
| 29764 | function updateOptions() { |
| 29765 | var previousValue = options && selectCtrl.readValue(); |
| 29766 | |
| 29767 | // We must remove all current options, but cannot simply set innerHTML = null |
| 29768 | // since the providedEmptyOption might have an ngIf on it that inserts comments which we |
| 29769 | // must preserve. |
| 29770 | // Instead, iterate over the current option elements and remove them or their optgroup |
| 29771 | // parents |
| 29772 | if (options) { |
| 29773 | |
| 29774 | for (var i = options.items.length - 1; i >= 0; i--) { |
| 29775 | var option = options.items[i]; |
| 29776 | if (isDefined(option.group)) { |
| 29777 | jqLiteRemove(option.element.parentNode); |
| 29778 | } else { |
| 29779 | jqLiteRemove(option.element); |
| 29780 | } |
| 29781 | } |
| 29782 | } |
| 29783 | |
| 29784 | options = ngOptions.getOptions(); |
| 29785 | |
| 29786 | var groupElementMap = {}; |
| 29787 | |
| 29788 | // Ensure that the empty option is always there if it was explicitly provided |
| 29789 | if (providedEmptyOption) { |
| 29790 | selectElement.prepend(emptyOption); |
| 29791 | } |
| 29792 | |
| 29793 | options.items.forEach(function addOption(option) { |
| 29794 | var groupElement; |
| 29795 | |
| 29796 | if (isDefined(option.group)) { |
| 29797 | |
| 29798 | // This option is to live in a group |
| 29799 | // See if we have already created this group |
| 29800 | groupElement = groupElementMap[option.group]; |
| 29801 | |
| 29802 | if (!groupElement) { |
| 29803 | |
| 29804 | groupElement = optGroupTemplate.cloneNode(false); |
| 29805 | listFragment.appendChild(groupElement); |
| 29806 | |
| 29807 | // Update the label on the group element |
| 29808 | // "null" is special cased because of Safari |
| 29809 | groupElement.label = option.group === null ? 'null' : option.group; |
| 29810 | |
| 29811 | // Store it for use later |
| 29812 | groupElementMap[option.group] = groupElement; |
| 29813 | } |
| 29814 | |
| 29815 | addOptionElement(option, groupElement); |
| 29816 | |
| 29817 | } else { |
| 29818 | |
| 29819 | // This option is not in a group |
| 29820 | addOptionElement(option, listFragment); |
| 29821 | } |
no test coverage detected