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

Commit be2fd2c

Browse files
committed
fix(modal): dismiss modal on unschedule destruction
- Dismiss modal via `modalInstance.dismiss` if the `$scope` undergoes an unscheduled destruction
1 parent 707fbf5 commit be2fd2c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/modal/modal.js

+8
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ angular.module('ui.bootstrap.modal', [])
375375
$modalStack.close = function (modalInstance, result) {
376376
var modalWindow = openedWindows.get(modalInstance);
377377
if (modalWindow && broadcastClosing(modalWindow, result, true)) {
378+
modalWindow.value.modalScope.$$uibDestructionScheduled = true;
378379
modalWindow.value.deferred.resolve(result);
379380
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
380381
return true;
@@ -385,6 +386,7 @@ angular.module('ui.bootstrap.modal', [])
385386
$modalStack.dismiss = function (modalInstance, reason) {
386387
var modalWindow = openedWindows.get(modalInstance);
387388
if (modalWindow && broadcastClosing(modalWindow, reason, false)) {
389+
modalWindow.value.modalScope.$$uibDestructionScheduled = true;
388390
modalWindow.value.deferred.reject(reason);
389391
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
390392
return true;
@@ -524,6 +526,12 @@ angular.module('ui.bootstrap.modal', [])
524526
modalScope.$close = modalInstance.close;
525527
modalScope.$dismiss = modalInstance.dismiss;
526528

529+
modalScope.$on('$destroy', function() {
530+
if (!modalScope.$$uibDestructionScheduled) {
531+
modalScope.$dismiss('$uibModal');
532+
}
533+
});
534+
527535
var ctrlInstance, ctrlLocals = {};
528536
var resolveIter = 1;
529537

0 commit comments

Comments
 (0)