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

Commit

Permalink
fix(modal): defer promise resolution until animation starts
Browse files Browse the repository at this point in the history
- Defer resolution of modalInstance promise until the animation cycle starts
  • Loading branch information
wesleycho committed Jun 26, 2015
1 parent 988336c commit 0cd27b9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
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

0 comments on commit 0cd27b9

Please sign in to comment.