From dfc36fd94b87bde6c49201f35bac469788dbe0c9 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 22 Jan 2014 21:01:14 +0100 Subject: [PATCH] fix(modal): destroy modal scope after animation end Fixes #1643 --- src/modal/modal.js | 5 ++++- src/modal/test/modal.spec.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modal/modal.js b/src/modal/modal.js index 26fe849335..e5bcdb8815 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -141,7 +141,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) openedWindows.remove(modalInstance); //remove window DOM element - removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, checkRemoveBackdrop); + removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, function() { + modalWindow.modalScope.$destroy(); + checkRemoveBackdrop(); + }); body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0); } diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 55bb9782a5..6c6259a15b 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -335,7 +335,7 @@ describe('$modal', function () { describe('scope', function () { - it('should custom scope if provided', function () { + it('should use custom scope if provided', function () { var $scope = $rootScope.$new(); $scope.fromScope = 'Content from custom scope'; open({ @@ -344,6 +344,17 @@ describe('$modal', function () { }); expect($document).toHaveModalOpenWithContent('Content from custom scope', 'div'); }); + + it('should create and use child of $rootScope if custom scope not provided', function () { + + var scopeTailBefore = $rootScope.$$childTail; + + $rootScope.fromScope = 'Content from root scope'; + open({ + template: '
{{fromScope}}
' + }); + expect($document).toHaveModalOpenWithContent('Content from root scope', 'div'); + }); }); describe('keyboard', function () {