Skip to content

Commit c11a7d6

Browse files
arm1nNarretz
authored andcommitted
fix(ngOptions): allow empty option selection with multiple attribute
Fixes angular#12511 Closes angular#12541
1 parent 0827e88 commit c11a7d6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ng/directive/ngOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
526526

527527
forEach(selectedValues, function(value) {
528528
var option = options.selectValueMap[value];
529-
if (!option.disabled) selections.push(options.getViewValueFromOption(option));
529+
if (option && !option.disabled) selections.push(options.getViewValueFromOption(option));
530530
});
531531

532532
return selections;

test/ng/directive/ngOptionsSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,18 @@ describe('ngOptions', function() {
20582058
// ensure the option has not changed following the digest
20592059
expect(element[0].selectedIndex).toEqual(0);
20602060
});
2061+
2062+
2063+
it('should be selectable if select is multiple', function() {
2064+
createMultiSelect(true);
2065+
2066+
// select the empty option
2067+
setSelectValue(element, 0);
2068+
2069+
// ensure selection and correct binding
2070+
expect(element[0].selectedIndex).toEqual(0);
2071+
expect(scope.selected).toEqual([]);
2072+
});
20612073
});
20622074

20632075

0 commit comments

Comments
 (0)