From be2fd2c57119b8abf9160f450235a3fbdc064639 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Mon, 3 Aug 2015 20:18:35 -0700 Subject: [PATCH] fix(modal): dismiss modal on unschedule destruction - Dismiss modal via `modalInstance.dismiss` if the `$scope` undergoes an unscheduled destruction --- src/modal/modal.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modal/modal.js b/src/modal/modal.js index 784688b92a..89ab44134c 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -375,6 +375,7 @@ angular.module('ui.bootstrap.modal', []) $modalStack.close = function (modalInstance, result) { var modalWindow = openedWindows.get(modalInstance); if (modalWindow && broadcastClosing(modalWindow, result, true)) { + modalWindow.value.modalScope.$$uibDestructionScheduled = true; modalWindow.value.deferred.resolve(result); removeModalWindow(modalInstance, modalWindow.value.modalOpener); return true; @@ -385,6 +386,7 @@ angular.module('ui.bootstrap.modal', []) $modalStack.dismiss = function (modalInstance, reason) { var modalWindow = openedWindows.get(modalInstance); if (modalWindow && broadcastClosing(modalWindow, reason, false)) { + modalWindow.value.modalScope.$$uibDestructionScheduled = true; modalWindow.value.deferred.reject(reason); removeModalWindow(modalInstance, modalWindow.value.modalOpener); return true; @@ -524,6 +526,12 @@ angular.module('ui.bootstrap.modal', []) modalScope.$close = modalInstance.close; modalScope.$dismiss = modalInstance.dismiss; + modalScope.$on('$destroy', function() { + if (!modalScope.$$uibDestructionScheduled) { + modalScope.$dismiss('$uibModal'); + } + }); + var ctrlInstance, ctrlLocals = {}; var resolveIter = 1;