Skip to content

Commit 4a06adb

Browse files
maxfierkewesleycho
authored andcommitted
fix(dropdown): Fix $digest:inprog on dropdown dismissal
Make $apply first check if $rootScope is in $digest cycle before executing Closes angular-ui#3274
1 parent 31c2694 commit 4a06adb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: src/dropdown/dropdown.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ angular.module('ui.bootstrap.dropdown', [])
44
openClass: 'open'
55
})
66

7-
.service('dropdownService', ['$document', function($document) {
7+
.service('dropdownService', ['$document', '$rootScope', function($document, $rootScope) {
88
var openScope = null;
99

1010
this.open = function( dropdownScope ) {
@@ -38,9 +38,11 @@ angular.module('ui.bootstrap.dropdown', [])
3838
return;
3939
}
4040

41-
openScope.$apply(function() {
42-
openScope.isOpen = false;
43-
});
41+
openScope.isOpen = false;
42+
43+
if (!$rootScope.$$phase) {
44+
openScope.$apply();
45+
}
4446
};
4547

4648
var escapeKeyBind = function( evt ) {

Diff for: src/dropdown/test/dropdown.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ describe('dropdownToggle', function() {
166166
clickDropdownToggle();
167167
expect(toggleEl.attr('aria-expanded')).toBe('false');
168168
});
169+
170+
// pr/issue 3274
171+
it('should not raise $digest:inprog if dismissed during a digest cycle', function () {
172+
clickDropdownToggle();
173+
expect(element.hasClass('open')).toBe(true);
174+
175+
$rootScope.$apply(function () {
176+
$document.click();
177+
});
178+
179+
expect(element.hasClass('open')).toBe(false);
180+
});
169181
});
170182

171183
describe('integration with $location URL rewriting', function() {

0 commit comments

Comments
 (0)