diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index 42b36bef42..e01c830847 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -29,6 +29,10 @@ angular.module('ui.bootstrap.dropdown', []) }; var closeDropdown = function( evt ) { + // This method may still be called during the same mouse event that + // unbound this event handler. So check openScope before proceeding. + if (!openScope) { return; } + var toggleElement = openScope.getToggleElement(); if ( evt && toggleElement && toggleElement[0].contains(evt.target) ) { return; diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 2bc379708a..262549aeea 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -168,6 +168,33 @@ describe('dropdownToggle', function() { }); }); + describe('integration with $location URL rewriting', function() { + function dropdown() { + + // Simulate URL rewriting behavior + $document.on('click', 'a[href="#something"]', function () { + $rootScope.$broadcast('$locationChangeSuccess'); + $rootScope.$apply(); + }); + + return $compile('
  • ' + + '
  • ')($rootScope); + } + + beforeEach(function() { + element = dropdown(); + }); + + it('should close without errors on $location change', function() { + $document.find('body').append(element); + clickDropdownToggle(); + expect(element.hasClass('open')).toBe(true); + var optionEl = element.find('ul > li').eq(0).find('a').eq(0); + optionEl.click(); + expect(element.hasClass('open')).toBe(false); + }); + }); + describe('without trigger', function() { beforeEach(function() { $rootScope.isopen = true;