diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 0b562cca686c..0135521bf033 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -575,6 +575,11 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { while(optionGroupsCache.length > groupIndex) { optionGroupsCache.pop()[0].element.remove(); } + + if(!multiple && !selectedSet && modelValue !== null) { + // no value selected, clear model + ctrl.$setViewValue(undefined); + } } } } diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 6fcd1fe05f82..afdf91671ec1 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -1113,6 +1113,28 @@ describe('select', function() { browserTrigger(element, 'change'); expect(scope.selected).toEqual(null); }); + + it('should clear model if ng-options change to not include selected value (#6379)', function() { + createSelect({ + 'ng-model': 'selected', + 'ng-options': 'item for item in values' + }); + + scope.$apply(function() { + scope.values = ['A','B']; + scope.selected = scope.values[0]; + }); + + expect(element.val()).toEqual('0'); + + expect(scope.selected).toEqual(scope.values[0]); + + scope.$apply(function() { + scope.values = ['C','D']; + }); + expect(element.val()).toEqual('?'); + expect(scope.selected).toBeUndefined(); + }); });