This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
ngView cleanup order #7606
Closed
Description
@matsko I think the ngView cleanup order is incorrect. Current it's:
function cleanupLastView() {
if(previousElement) {
previousElement.remove();
previousElement = null;
}
if(currentScope) {
currentScope.$destroy();
currentScope = null;
}
if(currentElement) {
$animate.leave(currentElement, function() {
previousElement = null;
});
previousElement = currentElement;
currentElement = null;
}
}
So a user lands on a page, the first view is shown, and currentElement
is set. Next the user clicks on a link to go to the second view. cleanupLastView()
gets called and should cleanup the first view. But previousElement
is undefined still (it gets set below which is too late) and so the cleanup does not happen.
Only after navigating to a third view is previousElement
defined and the cleanup starts to work.
Also it seems to me like the scope should be destroyed before the element is removed, but maybe that doesn't matter.
Correct me if I'm wrong but I think the order should be:
function cleanupLastView() {
if(currentElement) {
$animate.leave(currentElement, function() {
previousElement = null;
});
previousElement = currentElement;
currentElement = null;
}
if(currentScope) {
currentScope.$destroy();
currentScope = null;
}
if(previousElement) {
previousElement.remove();
previousElement = null;
}
}