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

fix(modal): defer promise resolution until animation starts #3806

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,11 @@ angular.module('ui.bootstrap.modal', [])
$modalStack.close = function (modalInstance, result) {
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow && broadcastClosing(modalWindow, result, true)) {
modalWindow.value.deferred.resolve(result);
// Defer resolution until after modal window is closed - #3787
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
$timeout(function() {
modalWindow.value.deferred.resolve(result);
});
return true;
}
return !modalWindow;
Expand All @@ -334,8 +337,11 @@ angular.module('ui.bootstrap.modal', [])
$modalStack.dismiss = function (modalInstance, reason) {
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow && broadcastClosing(modalWindow, reason, false)) {
modalWindow.value.deferred.reject(reason);
// Defer rejection until after modal window is dismissed - #3787
removeModalWindow(modalInstance, modalWindow.value.modalOpener);
$timeout(function() {
modalWindow.value.deferred.reject(reason);
});
return true;
}
return !modalWindow;
Expand Down
34 changes: 34 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,40 @@ describe('$modal', function () {
expect($document.find('.modal-backdrop')).not.toHaveClass('fade');
});

it('should resolve the promise after the animation starts', function () {
var modal = open({
template: '<div>Small modal dialog</div>',
animation: false
});

expect($document).toHaveModalsOpen(1);

modal.result.then(function() {
expect($document).toHaveModalsOpen(0);
}, function() {
expect(true).toBe(false);
});

close(modal);
});


it('should reject the promise after the animation starts', function () {
var modal = open({
template: '<div>Small modal dialog</div>',
animation: false
});

expect($document).toHaveModalsOpen(1);

modal.result.then(function() {
expect(true).toBe(false);
}, function() {
expect($document).toHaveModalsOpen(0);
});

dismiss(modal);
});
});

});
Expand Down