(scope, selectElement, attr, ctrls)
| 32503 | optGroupTemplate = window.document.createElement('optgroup'); |
| 32504 | |
| 32505 | function ngOptionsPostLink(scope, selectElement, attr, ctrls) { |
| 32506 | |
| 32507 | var selectCtrl = ctrls[0]; |
| 32508 | var ngModelCtrl = ctrls[1]; |
| 32509 | var multiple = attr.multiple; |
| 32510 | |
| 32511 | // The emptyOption allows the application developer to provide their own custom "empty" |
| 32512 | // option when the viewValue does not match any of the option values. |
| 32513 | for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++) { |
| 32514 | if (children[i].value === '') { |
| 32515 | selectCtrl.hasEmptyOption = true; |
| 32516 | selectCtrl.emptyOption = children.eq(i); |
| 32517 | break; |
| 32518 | } |
| 32519 | } |
| 32520 | |
| 32521 | // The empty option will be compiled and rendered before we first generate the options |
| 32522 | selectElement.empty(); |
| 32523 | |
| 32524 | var providedEmptyOption = !!selectCtrl.emptyOption; |
| 32525 | |
| 32526 | var unknownOption = jqLite(optionTemplate.cloneNode(false)); |
| 32527 | unknownOption.val('?'); |
| 32528 | |
| 32529 | var options; |
| 32530 | var ngOptions = parseOptionsExpression(attr.ngOptions, selectElement, scope); |
| 32531 | // This stores the newly created options before they are appended to the select. |
| 32532 | // Since the contents are removed from the fragment when it is appended, |
| 32533 | // we only need to create it once. |
| 32534 | var listFragment = $document[0].createDocumentFragment(); |
| 32535 | |
| 32536 | // Overwrite the implementation. ngOptions doesn't use hashes |
| 32537 | selectCtrl.generateUnknownOptionValue = function(val) { |
| 32538 | return '?'; |
| 32539 | }; |
| 32540 | |
| 32541 | // Update the controller methods for multiple selectable options |
| 32542 | if (!multiple) { |
| 32543 | |
| 32544 | selectCtrl.writeValue = function writeNgOptionsValue(value) { |
| 32545 | // The options might not be defined yet when ngModel tries to render |
| 32546 | if (!options) return; |
| 32547 | |
| 32548 | var selectedOption = selectElement[0].options[selectElement[0].selectedIndex]; |
| 32549 | var option = options.getOptionFromViewValue(value); |
| 32550 | |
| 32551 | // Make sure to remove the selected attribute from the previously selected option |
| 32552 | // Otherwise, screen readers might get confused |
| 32553 | if (selectedOption) selectedOption.removeAttribute('selected'); |
| 32554 | |
| 32555 | if (option) { |
| 32556 | // Don't update the option when it is already selected. |
| 32557 | // For example, the browser will select the first option by default. In that case, |
| 32558 | // most properties are set automatically - except the `selected` attribute, which we |
| 32559 | // set always |
| 32560 | |
| 32561 | if (selectElement[0].value !== option.selectValue) { |
| 32562 | selectCtrl.removeUnknownOption(); |
nothing calls this directly
no test coverage detected