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

Commit

Permalink
fix(modal): dismiss modal on unschedule destruction
Browse files Browse the repository at this point in the history
- Dismiss modal via `modalInstance.dismiss` if the `$scope` undergoes an unscheduled destruction
  • Loading branch information
wesleycho committed Aug 4, 2015
1 parent 707fbf5 commit be2fd2c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit be2fd2c

Please sign in to comment.