Angular 2 - Is ngOnDestroy called when updating or just when moving from a component?

I'm trying to find out if ngOnDestroy starts in Angular 2 when updating or just when someone moves away from the page?

+7
angular
source share
1 answer

When updating or when moving away from the current page, ngOnDestroy will not be called. The application will simply be destroyed by the browser.

Only when Angular2 removes a component from the DOM because you are leaving or you are calling destroy() on a dynamically created component is ngOnDestroy() called.

You can listen to beforeunload and unload yourself if you need some action before the application is destroyed by the browser.

see also

+8
source share

All Articles