Skip to content

Commit 4d2db08

Browse files
author
Colin Huang
committed
fix(modal): Destroy modal scope in removeModalWindow
Fix for issue #138 Test case included
1 parent f8ef93c commit 4d2db08

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/modal/modal.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,18 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
140140
});
141141

142142
function removeModalWindow(modalInstance) {
143-
144143
var body = $document.find('body').eq(0);
145144
var modalWindow = openedWindows.get(modalInstance).value;
146145

147146
//clean up the stack
148147
openedWindows.remove(modalInstance);
149148

150149
//remove window DOM element
151-
removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, checkRemoveBackdrop);
152-
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
150+
removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, function() {
151+
modalWindow.modalScope.$destroy();
152+
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
153+
checkRemoveBackdrop();
154+
});
153155
}
154156

155157
function checkRemoveBackdrop() {
@@ -228,7 +230,7 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
228230
backdropDomEl = $compile('<div modal-backdrop></div>')(backdropScope);
229231
body.append(backdropDomEl);
230232
}
231-
233+
232234
// Create a faux modal div just to measure its
233235
// distance to top
234236
var faux = angular.element('<div class="reveal-modal" style="z-index:-1""></div>');

src/modal/test/modal.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ describe('$modal', function () {
207207
expect(modal.opened).toBeRejectedWith(false);
208208
});
209209

210+
it('should destroy modal scope on close', function () {
211+
expect($rootScope.$$childTail).toEqual(null);
212+
213+
var modal = open({template: '<div>Content</div>'});
214+
expect($rootScope.$$childTail).toNotEqual(null);
215+
216+
close(modal, 'closed ok');
217+
waitForBackdropAnimation();
218+
expect($document).toHaveModalsOpen(0);
219+
220+
$timeout.flush();
221+
expect($rootScope.$$childTail).toEqual(null);
222+
});
210223
});
211224

212225
describe('default options can be changed in a provider', function () {

0 commit comments

Comments
 (0)