diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index e01c830847..14c255a13b 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -4,7 +4,7 @@ angular.module('ui.bootstrap.dropdown', []) openClass: 'open' }) -.service('dropdownService', ['$document', function($document) { +.service('dropdownService', ['$document', '$rootScope', function($document, $rootScope) { var openScope = null; this.open = function( dropdownScope ) { @@ -38,9 +38,11 @@ angular.module('ui.bootstrap.dropdown', []) return; } - openScope.$apply(function() { - openScope.isOpen = false; - }); + openScope.isOpen = false; + + if (!$rootScope.$$phase) { + openScope.$apply(); + } }; var escapeKeyBind = function( evt ) { diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 262549aeea..c1c46a85ee 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -166,6 +166,18 @@ describe('dropdownToggle', function() { clickDropdownToggle(); expect(toggleEl.attr('aria-expanded')).toBe('false'); }); + + // pr/issue 3274 + it('should not raise $digest:inprog if dismissed during a digest cycle', function () { + clickDropdownToggle(); + expect(element.hasClass('open')).toBe(true); + + $rootScope.$apply(function () { + $document.click(); + }); + + expect(element.hasClass('open')).toBe(false); + }); }); describe('integration with $location URL rewriting', function() {