On refresh or when you navigate away from the current page (except for routing), then ngOnDestroy
won’t be called. The application will just be destroyed by the browser.
Only when Angular2 removes the component from the DOM because you move away or you call destroy()
on a dynamically created component, then ngOnDestroy()
is called.
You can listen to beforeunload
and unload
yourself if you need some action to happen before the application is destroyed by the browser.
See also