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

Commit 0cd27b9

Browse files
committed
fix(modal): defer promise resolution until animation starts
- Defer resolution of modalInstance promise until the animation cycle starts
1 parent 988336c commit 0cd27b9

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

Diff for: src/modal/modal.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ angular.module('ui.bootstrap.modal', [])
324324
$modalStack.close = function (modalInstance, result) {
325325
var modalWindow = openedWindows.get(modalInstance);
326326
if (modalWindow && broadcastClosing(modalWindow, result, true)) {
327-
modalWindow.value.deferred.resolve(result);
327+
// Defer resolution until after modal window is closed - #3787
328328
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
329+
$timeout(function() {
330+
modalWindow.value.deferred.resolve(result);
331+
});
329332
return true;
330333
}
331334
return !modalWindow;
@@ -334,8 +337,11 @@ angular.module('ui.bootstrap.modal', [])
334337
$modalStack.dismiss = function (modalInstance, reason) {
335338
var modalWindow = openedWindows.get(modalInstance);
336339
if (modalWindow && broadcastClosing(modalWindow, reason, false)) {
337-
modalWindow.value.deferred.reject(reason);
340+
// Defer rejection until after modal window is dismissed - #3787
338341
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
342+
$timeout(function() {
343+
modalWindow.value.deferred.reject(reason);
344+
});
339345
return true;
340346
}
341347
return !modalWindow;

Diff for: src/modal/test/modal.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,40 @@ describe('$modal', function () {
673673
expect($document.find('.modal-backdrop')).not.toHaveClass('fade');
674674
});
675675

676+
it('should resolve the promise after the animation starts', function () {
677+
var modal = open({
678+
template: '<div>Small modal dialog</div>',
679+
animation: false
680+
});
681+
682+
expect($document).toHaveModalsOpen(1);
683+
684+
modal.result.then(function() {
685+
expect($document).toHaveModalsOpen(0);
686+
}, function() {
687+
expect(true).toBe(false);
688+
});
689+
690+
close(modal);
691+
});
692+
693+
694+
it('should reject the promise after the animation starts', function () {
695+
var modal = open({
696+
template: '<div>Small modal dialog</div>',
697+
animation: false
698+
});
699+
700+
expect($document).toHaveModalsOpen(1);
701+
702+
modal.result.then(function() {
703+
expect(true).toBe(false);
704+
}, function() {
705+
expect($document).toHaveModalsOpen(0);
706+
});
707+
708+
dismiss(modal);
709+
});
676710
});
677711

678712
});

0 commit comments

Comments
 (0)