From 9e305948e4965fb86b0c79985dc6e8c59a9c66af Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Thu, 6 Nov 2014 22:29:53 +0100 Subject: [PATCH] fix(select): use strict comparison for isSelected with selectAs Closes #9639 Closes #9949 --- src/ng/directive/select.js | 2 +- test/ng/directive/selectSpec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 9d7dd84a376d..f00228a91413 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -483,7 +483,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { if (multiple) { return isDefined(selectedSet.remove(callExpression(compareValueFn, key, value))); } else { - return viewValue == callExpression(compareValueFn, key, value); + return viewValue === callExpression(compareValueFn, key, value); } }; } diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 7aa91b97fcfb..412e6e4c8b69 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -1629,6 +1629,20 @@ describe('select', function() { expect(element.val()).toEqual('?'); expect(element.find('option').eq(0).attr('selected')).toEqual('selected'); }); + + + it('should select the correct option for selectAs and falsy values', function() { + scope.values = [{value: 0, label: 'zero'}, {value: 1, label: 'one'}]; + scope.selected = ''; + createSelect({ + 'ng-model': 'selected', + 'ng-options': 'option.value as option.label for option in values' + }); + + var option = element.find('option').eq(0); + expect(option.val()).toBe('?'); + expect(option.text()).toBe(''); + }); });