From 10b876fb293050b0d90b33baa4ab0feab6c6092a Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Thu, 14 May 2015 15:14:31 +0100 Subject: [PATCH] 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 Closes #11872 --- src/ng/directive/select.js | 2 +- test/ng/directive/selectSpec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 990b712dc405..66c5843c2ecd 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -59,7 +59,7 @@ var SelectController = $element.val(value); if (value === '') self.emptyOption.prop('selected', true); // to make IE9 happy } else { - if (isUndefined(value) && self.emptyOption) { + if (value == null && self.emptyOption) { self.removeUnknownOption(); $element.val(''); } else { diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index ac4bc0111aa0..3aca6176ec97 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -404,7 +404,7 @@ describe('select', function() { scope.$apply(function() { scope.robot = null; }); - expect(element).toEqualSelect([unknownValue(null)], '', 'c3p0', 'r2d2'); + expect(element).toEqualSelect([''], 'c3p0', 'r2d2'); scope.$apply(function() { scope.robot = 'r2d2';