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

Commit

Permalink
feat(modal): dismiss all modals on $locationChangeSuccess
Browse files Browse the repository at this point in the history
Closes #1334
  • Loading branch information
pkozlowski-opensource committed Jan 9, 2014
1 parent 6eb9c2a commit a250d91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
}
});

$rootScope.$on('$locationChangeSuccess', function () {
var topModal = $modalStack.getTop();
while (topModal) {
$modalStack.dismiss(topModal.key, '$locationChangeSuccess');
topModal = $modalStack.getTop();
}
});

function removeModalWindow(modalInstance) {

var body = $document.find('body').eq(0);
Expand Down
15 changes: 14 additions & 1 deletion src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ describe('$modal', function () {
expect($document).toHaveModalOpenWithContent('Content', 'div');
expect($document).not.toHaveBackdrop();
});

});

describe('option by option', function () {
Expand Down Expand Up @@ -487,5 +486,19 @@ describe('$modal', function () {
dismiss(modal2);
expect(body).not.toHaveClass('modal-open');
});

it('should close all open modals on $locationChangeSuccess', function () {
var modal1 = open({template: '<div>Modal1</div>'});
var modal2 = open({template: '<div>Modal2</div>'});

$rootScope.$digest();
expect($document).toHaveModalsOpen(2);

$rootScope.$broadcast('$locationChangeSuccess');
$timeout.flush();
$rootScope.$digest();

expect($document).toHaveModalsOpen(0);
});
});
});

0 comments on commit a250d91

Please sign in to comment.