Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modal): Destroy modal scope in removeModalWindow() #139

Merged
merged 1 commit into from
Nov 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,18 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
});

function removeModalWindow(modalInstance) {

var body = $document.find('body').eq(0);
var modalWindow = openedWindows.get(modalInstance).value;

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

//remove window DOM element
removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, checkRemoveBackdrop);
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 300, function() {
modalWindow.modalScope.$destroy();
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
checkRemoveBackdrop();
});
}

function checkRemoveBackdrop() {
Expand Down Expand Up @@ -228,7 +230,7 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
backdropDomEl = $compile('<div modal-backdrop></div>')(backdropScope);
body.append(backdropDomEl);
}

// Create a faux modal div just to measure its
// distance to top
var faux = angular.element('<div class="reveal-modal" style="z-index:-1""></div>');
Expand Down
13 changes: 13 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ describe('$modal', function () {
expect(modal.opened).toBeRejectedWith(false);
});

it('should destroy modal scope on close', function () {
expect($rootScope.$$childTail).toEqual(null);

var modal = open({template: '<div>Content</div>'});
expect($rootScope.$$childTail).toNotEqual(null);

close(modal, 'closed ok');
waitForBackdropAnimation();
expect($document).toHaveModalsOpen(0);

$timeout.flush();
expect($rootScope.$$childTail).toEqual(null);
});
});

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