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: '