diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index d82bd139c3b2..7e110e7159d4 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -468,7 +468,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { if (existingOption.id !== option.id) { lastElement.val(existingOption.id = option.id); } - if (existingOption.element.selected !== option.selected) { + if (!!lastElement.selected !== option.selected) { lastElement.prop('selected', (existingOption.selected = option.selected)); } } else { diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 2b56228d17c9..c143404bc0dc 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -977,6 +977,19 @@ describe('select', function() { expect(option.attr('id')).toBe('road-runner'); expect(option.attr('custom-attr')).toBe('custom-attr'); }); + + it ('should select the null option, if it\'s available and no other option is selected', inject(function($timeout) { + // selectedIndex is used here because jqLite incorrectly reports element.val() + scope.$apply(function() { + scope.values = [{name: 'A'}]; + }); + createSingleSelect(true); + // ensure the first option (the null option) is selected + expect(element[0].selectedIndex).toEqual(0); + scope.$digest(); + // ensure the option has not changed following the digest + expect(element[0].selectedIndex).toEqual(0); + })); });