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

Commit 9e3f82b

Browse files
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 0515614 commit 9e3f82b

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
@@ -316,7 +316,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
316316
selectElement.val(viewValue);
317317
if (viewValue === '') emptyOption.prop('selected', true); // to make IE9 happy
318318
} else {
319-
if (isUndefined(viewValue) && emptyOption) {
319+
if (viewValue == null && emptyOption) {
320320
selectElement.val('');
321321
} else {
322322
selectCtrl.renderUnknownOption(viewValue);

test/ng/directive/selectSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ describe('select', function() {
362362
scope.$apply(function() {
363363
scope.robot = null;
364364
});
365-
expect(element).toEqualSelect(['? object:null ?'], '', 'c3p0', 'r2d2');
365+
expect(element).toEqualSelect([''], 'c3p0', 'r2d2');
366366

367367
scope.$apply(function() {
368368
scope.robot = 'r2d2';

0 commit comments

Comments
 (0)