fix(ivy): OnDestroy hook should not be called twice for a directive on an element (#22350)

PR Close #22350
This commit is contained in:
Marc Laval
2018-02-21 15:08:18 +01:00
committed by Victor Berchet
parent f194d00366
commit b3ffeaa22b
2 changed files with 147 additions and 7 deletions

View File

@ -233,7 +233,9 @@ export function destroyViewTree(rootView: LView): void {
}
if (next == null) {
while (viewOrContainer && !viewOrContainer !.next) {
// If the viewOrContainer is the rootView, then the cleanup is done twice.
// Without this check, ngOnDestroy would be called twice for a directive on an element.
while (viewOrContainer && !viewOrContainer !.next && viewOrContainer !== rootView) {
cleanUpView(viewOrContainer as LView);
viewOrContainer = getParentState(viewOrContainer, rootView);
}