Skip to content

Commit ab41f28

Browse files
committed
fix(ngOptions): always set the 'selected' attribute for selected options
We don't set selected property / attribute on options that are already selected. That happens for example if the browser has automatically selected the first option in a select. In that case, the selected property is set automatically, but the selected attribute is not Closes angular#14115
1 parent ddd7b48 commit ab41f28

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ng/directive/ngOptions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,17 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
468468
var option = options.getOptionFromViewValue(value);
469469

470470
if (option && !option.disabled) {
471+
// Don't update the option when it is already selected.
472+
// For example, the browser will select the first option by default. In that case,
473+
// most properties are set automatically - except the `selected` attribute.
474+
option.element.setAttribute('selected', 'selected');
475+
471476
if (selectElement[0].value !== option.selectValue) {
472477
removeUnknownOption();
473478
removeEmptyOption();
474479

475480
selectElement[0].value = option.selectValue;
476481
option.element.selected = true;
477-
option.element.setAttribute('selected', 'selected');
478482
}
479483
} else {
480484
if (value === null || providedEmptyOption) {

0 commit comments

Comments
 (0)