MCPcopy Index your code
hub / github.com/angular-ui/ui-router / ngOptionsPostLink

Function ngOptionsPostLink

test/angular/1.5/angular.js:29520–29839  ·  view source on GitHub ↗
(scope, selectElement, attr, ctrls)

Source from the content-addressed store, hash-verified

29518 optGroupTemplate = window.document.createElement('optgroup');
29519
29520 function ngOptionsPostLink(scope, selectElement, attr, ctrls) {
29521
29522 var selectCtrl = ctrls[0];
29523 var ngModelCtrl = ctrls[1];
29524 var multiple = attr.multiple;
29525
29526 // The emptyOption allows the application developer to provide their own custom "empty"
29527 // option when the viewValue does not match any of the option values.
29528 var emptyOption;
29529 for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++) {
29530 if (children[i].value === '') {
29531 emptyOption = children.eq(i);
29532 break;
29533 }
29534 }
29535
29536 var providedEmptyOption = !!emptyOption;
29537 var emptyOptionRendered = false;
29538
29539 var unknownOption = jqLite(optionTemplate.cloneNode(false));
29540 unknownOption.val('?');
29541
29542 var options;
29543 var ngOptions = parseOptionsExpression(attr.ngOptions, selectElement, scope);
29544 // This stores the newly created options before they are appended to the select.
29545 // Since the contents are removed from the fragment when it is appended,
29546 // we only need to create it once.
29547 var listFragment = $document[0].createDocumentFragment();
29548
29549 var renderEmptyOption = function() {
29550 if (!providedEmptyOption) {
29551 selectElement.prepend(emptyOption);
29552 }
29553 selectElement.val('');
29554 if (emptyOptionRendered) {
29555 emptyOption.prop('selected', true); // needed for IE
29556 emptyOption.attr('selected', true);
29557 }
29558 };
29559
29560 var removeEmptyOption = function() {
29561 if (!providedEmptyOption) {
29562 emptyOption.remove();
29563 } else if (emptyOptionRendered) {
29564 emptyOption.removeAttr('selected');
29565 }
29566 };
29567
29568 var renderUnknownOption = function() {
29569 selectElement.prepend(unknownOption);
29570 selectElement.val('?');
29571 unknownOption.prop('selected', true); // needed for IE
29572 unknownOption.attr('selected', true);
29573 };
29574
29575 var removeUnknownOption = function() {
29576 unknownOption.remove();
29577 };

Callers

nothing calls this directly

Calls 8

isArrayFunction · 0.85
parseOptionsExpressionFunction · 0.70
removeUnknownOptionFunction · 0.70
removeEmptyOptionFunction · 0.70
renderEmptyOptionFunction · 0.70
renderUnknownOptionFunction · 0.70
forEachFunction · 0.70
updateOptionsFunction · 0.70

Tested by

no test coverage detected