From a250d91ea240db81c4847bba42abdc02c2cde4d7 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 9 Jan 2014 21:35:54 +0100 Subject: [PATCH] feat(modal): dismiss all modals on $locationChangeSuccess Closes #1334 --- src/modal/modal.js | 8 ++++++++ src/modal/test/modal.spec.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/modal/modal.js b/src/modal/modal.js index ce1ec83d34..747fbf8190 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -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); diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 26b606d45f..54ed0bc35a 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -229,7 +229,6 @@ describe('$modal', function () { expect($document).toHaveModalOpenWithContent('Content', 'div'); expect($document).not.toHaveBackdrop(); }); - }); describe('option by option', function () { @@ -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: '
Modal1
'}); + var modal2 = open({template: '
Modal2
'}); + + $rootScope.$digest(); + expect($document).toHaveModalsOpen(2); + + $rootScope.$broadcast('$locationChangeSuccess'); + $timeout.flush(); + $rootScope.$digest(); + + expect($document).toHaveModalsOpen(0); + }); }); }); \ No newline at end of file