Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4090491

Browse files
divercraigpetebacondarwin
authored andcommitted
fix(select): prevent unknown option being added to select when bound to null property
If a select directive was bound, using ng-model, to a property with a value of null this would result in an unknown option being added to the select element with the value "? object:null ?". This change prevents a null value from adding an unknown option meaning that the extra option is not added as a child of the select element. Since select (without ngOptions) can only have string value options then `null` was never a viable option value, so this is not a breaking change. Closes #11872 Closes #11875
1 parent 5b18250 commit 4090491

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/ng/directive/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var SelectController =
5959
$element.val(value);
6060
if (value === '') self.emptyOption.prop('selected', true); // to make IE9 happy
6161
} else {
62-
if (isUndefined(value) && self.emptyOption) {
62+
if (value == null && self.emptyOption) {
6363
self.removeUnknownOption();
6464
$element.val('');
6565
} else {

test/ng/directive/selectSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe('select', function() {
404404
scope.$apply(function() {
405405
scope.robot = null;
406406
});
407-
expect(element).toEqualSelect([unknownValue(null)], '', 'c3p0', 'r2d2');
407+
expect(element).toEqualSelect([''], 'c3p0', 'r2d2');
408408

409409
scope.$apply(function() {
410410
scope.robot = 'r2d2';

0 commit comments

Comments
 (0)