diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index b583546d653f..59b505323d91 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -519,11 +519,16 @@ var selectDirective = function() { function selectPreLink(scope, element, attr, ctrls) { - // if ngModel is not defined, we don't need to do anything + var selectCtrl = ctrls[0]; var ngModelCtrl = ctrls[1]; - if (!ngModelCtrl) return; - var selectCtrl = ctrls[0]; + // if ngModel is not defined, we don't need to do anything but set the registerOption + // function to noop, so options don't get added internally + if (!ngModelCtrl) { + selectCtrl.registerOption = noop; + return; + } + selectCtrl.ngModelCtrl = ngModelCtrl; diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 9027aa657326..17f1a6b26f74 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -136,6 +136,30 @@ describe('select', function() { }); + it('should not add options to the select if ngModel is not present', inject(function($rootScope) { + var scope = $rootScope; + scope.d = 'd'; + scope.e = 'e'; + scope.f = 'f'; + + compile(''); + + var selectCtrl = element.controller('select'); + + expect(selectCtrl.hasOption('a')).toBe(false); + expect(selectCtrl.hasOption('b')).toBe(false); + expect(selectCtrl.hasOption('c')).toBe(false); + expect(selectCtrl.hasOption('d')).toBe(false); + expect(selectCtrl.hasOption('e')).toBe(false); + expect(selectCtrl.hasOption('f')).toBe(false); + })); describe('select-one', function() {