Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

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 #3274
  • Loading branch information
maxfierke authored and wesleycho committed Mar 30, 2015
1 parent 31c2694 commit 4a06adb
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 4a06adb

Please sign in to comment.