diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index f1c138a670..62c4582d6f 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -78,7 +78,7 @@ angular.module('ui.bootstrap.dropdown', []) } }; - scope.$watch('isOpen', function( isOpen ) { + scope.$watch('isOpen', function( isOpen, wasOpen ) { $animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass); if ( isOpen ) { @@ -89,7 +89,9 @@ angular.module('ui.bootstrap.dropdown', []) } setIsOpen($scope, isOpen); - toggleInvoker($scope, { open: !!isOpen }); + if (angular.isDefined(wasOpen) && isOpen !== wasOpen) { + toggleInvoker($scope, { open: !!isOpen }); + } }); $scope.$on('$locationChangeSuccess', function() { diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 77c7f509b9..d0bf45a2bd 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -212,16 +212,18 @@ describe('dropdownToggle', function() { describe('`on-toggle`', function() { beforeEach(function() { $rootScope.toggleHandler = jasmine.createSpy('toggleHandler'); - element = $compile('')($rootScope); + $rootScope.isopen = false; + element = $compile('')($rootScope); $rootScope.$digest(); }); - it('should be called initially', function() { - expect($rootScope.toggleHandler).toHaveBeenCalledWith(false); + it('should not have been called initially', function() { + expect($rootScope.toggleHandler).not.toHaveBeenCalled(); }); it('should call it correctly when toggles', function() { - clickDropdownToggle(); + $rootScope.isopen = true; + $rootScope.$digest(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(true); clickDropdownToggle(); @@ -237,8 +239,8 @@ describe('dropdownToggle', function() { $rootScope.$digest(); }); - it('should be called initially with true', function() { - expect($rootScope.toggleHandler).toHaveBeenCalledWith(true); + it('should not have been called initially', function() { + expect($rootScope.toggleHandler).not.toHaveBeenCalled(); }); it('should call it correctly when toggles', function() {