This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Dynamic select directive doesn't support empty value #11470
Closed
Description
Branch 1.2.X issue.
In case I have select directive which get options generated from server, it throws following error:
TypeError: 'undefined' is not an object (evaluating 'emptyOption.prop')
at /angularjs/angular-1.2.28.js:21717
at ngModelWatch (/angularjs/angular-1.2.28.js:17899)
at /angularjs/angular-1.2.28.js:12642
at /angularjs/angular-1.2.28.js:12915
in case I'm trying to update model in my test (it works perfectly fine when it comes to browser, but it can't update itself based on model change) and here's why. This piece of code executes when linking select initially:
for (var i = 0, children = element.children(), ii = children.length; i < ii; i++) {
if (children[i].value === '') {
emptyOption = nullOption = children.eq(i);
break;
}
}
and in this moment of course, my select doesn't have emptyOption. Later on, I populate options and try to update model in my test. Then this piece of code is triggered:
var viewValue = ngModelCtrl.$viewValue;
if (selectCtrl.hasOption(viewValue)) {
if (unknownOption.parent()) unknownOption.remove();
selectElement.val(viewValue);
if (viewValue === '') emptyOption.prop('selected', true); // to make IE9 happy
} else {
if (isUndefined(viewValue) && emptyOption) {
selectElement.val('');
} else {
selectCtrl.renderUnknownOption(viewValue);
}
}
Now, in this moment emptyOption is undefined, but I really do have it, only thing, it was generated later (after link function).
Can we(I can do it if you let me) have additional element.find when it comes to assigning to emptyOption?
Metadata
Metadata
Assignees
Labels
No labels