(scope, selectElement, attr, ctrls)
| 26998 | |
| 26999 | |
| 27000 | function ngOptionsPostLink(scope, selectElement, attr, ctrls) { |
| 27001 | |
| 27002 | // if ngModel is not defined, we don't need to do anything |
| 27003 | var ngModelCtrl = ctrls[1]; |
| 27004 | if (!ngModelCtrl) return; |
| 27005 | |
| 27006 | var selectCtrl = ctrls[0]; |
| 27007 | var multiple = attr.multiple; |
| 27008 | |
| 27009 | // The emptyOption allows the application developer to provide their own custom "empty" |
| 27010 | // option when the viewValue does not match any of the option values. |
| 27011 | var emptyOption; |
| 27012 | for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++) { |
| 27013 | if (children[i].value === '') { |
| 27014 | emptyOption = children.eq(i); |
| 27015 | break; |
| 27016 | } |
| 27017 | } |
| 27018 | |
| 27019 | var providedEmptyOption = !!emptyOption; |
| 27020 | |
| 27021 | var unknownOption = jqLite(optionTemplate.cloneNode(false)); |
| 27022 | unknownOption.val('?'); |
| 27023 | |
| 27024 | var options; |
| 27025 | var ngOptions = parseOptionsExpression(attr.ngOptions, selectElement, scope); |
| 27026 | |
| 27027 | |
| 27028 | var renderEmptyOption = function() { |
| 27029 | if (!providedEmptyOption) { |
| 27030 | selectElement.prepend(emptyOption); |
| 27031 | } |
| 27032 | selectElement.val(''); |
| 27033 | emptyOption.prop('selected', true); // needed for IE |
| 27034 | emptyOption.attr('selected', true); |
| 27035 | }; |
| 27036 | |
| 27037 | var removeEmptyOption = function() { |
| 27038 | if (!providedEmptyOption) { |
| 27039 | emptyOption.remove(); |
| 27040 | } |
| 27041 | }; |
| 27042 | |
| 27043 | |
| 27044 | var renderUnknownOption = function() { |
| 27045 | selectElement.prepend(unknownOption); |
| 27046 | selectElement.val('?'); |
| 27047 | unknownOption.prop('selected', true); // needed for IE |
| 27048 | unknownOption.attr('selected', true); |
| 27049 | }; |
| 27050 | |
| 27051 | var removeUnknownOption = function() { |
| 27052 | unknownOption.remove(); |
| 27053 | }; |
| 27054 | |
| 27055 | // Update the controller methods for multiple selectable options |
| 27056 | if (!multiple) { |
| 27057 |
nothing calls this directly
no test coverage detected