()
| 27249 | |
| 27250 | |
| 27251 | function updateOptions() { |
| 27252 | |
| 27253 | var previousValue = options && selectCtrl.readValue(); |
| 27254 | |
| 27255 | options = ngOptions.getOptions(); |
| 27256 | |
| 27257 | var groupMap = {}; |
| 27258 | var currentElement = selectElement[0].firstChild; |
| 27259 | |
| 27260 | // Ensure that the empty option is always there if it was explicitly provided |
| 27261 | if (providedEmptyOption) { |
| 27262 | selectElement.prepend(emptyOption); |
| 27263 | } |
| 27264 | |
| 27265 | currentElement = skipEmptyAndUnknownOptions(currentElement); |
| 27266 | |
| 27267 | options.items.forEach(function updateOption(option) { |
| 27268 | var group; |
| 27269 | var groupElement; |
| 27270 | var optionElement; |
| 27271 | |
| 27272 | if (option.group) { |
| 27273 | |
| 27274 | // This option is to live in a group |
| 27275 | // See if we have already created this group |
| 27276 | group = groupMap[option.group]; |
| 27277 | |
| 27278 | if (!group) { |
| 27279 | |
| 27280 | // We have not already created this group |
| 27281 | groupElement = addOrReuseElement(selectElement[0], |
| 27282 | currentElement, |
| 27283 | 'optgroup', |
| 27284 | optGroupTemplate); |
| 27285 | // Move to the next element |
| 27286 | currentElement = groupElement.nextSibling; |
| 27287 | |
| 27288 | // Update the label on the group element |
| 27289 | groupElement.label = option.group; |
| 27290 | |
| 27291 | // Store it for use later |
| 27292 | group = groupMap[option.group] = { |
| 27293 | groupElement: groupElement, |
| 27294 | currentOptionElement: groupElement.firstChild |
| 27295 | }; |
| 27296 | |
| 27297 | } |
| 27298 | |
| 27299 | // So now we have a group for this option we add the option to the group |
| 27300 | optionElement = addOrReuseElement(group.groupElement, |
| 27301 | group.currentOptionElement, |
| 27302 | 'option', |
| 27303 | optionTemplate); |
| 27304 | updateOptionElement(option, optionElement); |
| 27305 | // Move to the next element |
| 27306 | group.currentOptionElement = optionElement.nextSibling; |
| 27307 | |
| 27308 | } else { |
no test coverage detected