Skip to content

Commit

Permalink
fix(dropdown): Fix $digest:inprog on dropdown dismissal
Browse files Browse the repository at this point in the history
Make $apply first check if $rootScope is in $digest cycle before executing

Closes angular-ui#3274
  • Loading branch information
maxfierke authored and fernando-sendMail committed Jul 16, 2015
1 parent d1c6f48 commit 30735ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down
12 changes: 12 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 30735ea

Please sign in to comment.