diff --git a/src/modal/modal.js b/src/modal/modal.js index 67101c74d2..a910ae563a 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -201,6 +201,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) $q.when(animationPromise).then(function() { + // Notify {@link $modalStack} that modal is rendered. + var modal = $modalStack.getTop(); + if (modal) { + $modalStack.modalRendered(modal.key); + } + /** * If something within the freshly-opened modal already has focus (perhaps via a * directive that causes focus). then no need to try and focus anything. @@ -222,12 +228,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) } } }); - - // Notify {@link $modalStack} that modal is rendered. - var modal = $modalStack.getTop(); - if (modal) { - $modalStack.modalRendered(modal.key); - } }); } }; diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 676c0d30be..8e4d44e7e1 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -305,6 +305,42 @@ describe('$uibModal', function() { close(modalInstance, 'closing in test', true); }); + it('should resolve rendered promise when animation is complete', function() { + var modalInstance = { + result: $q.defer(), + opened: $q.defer(), + closed: $q.defer(), + rendered: $q.defer(), + close: function (result) { + return $uibModalStack.close(modalInstance, result); + }, + dismiss: function (reason) { + return $uibModalStack.dismiss(modalInstance, reason); + } + }; + var rendered = false; + modalInstance.rendered.promise.then(function() { + rendered = true; + }); + + $uibModalStack.open(modalInstance, { + appendTo: angular.element(document.body), + scope: $rootScope.$new(), + deferred: modalInstance.result, + renderDeferred: modalInstance.rendered, + closedDeferred: modalInstance.closed, + content: '
test
' + }); + + $rootScope.$digest(); + + expect(rendered).toBe(false); + + $animate.flush(); + + expect(rendered).toBe(true); + }); + it('should not throw an exception on a second dismiss', function() { var modal = open({template: '
Content
'});