I am trying to figure out if ngOnDestroy in Angular 2 gets ran on a refresh or just when someone navigates away from the page?
On refresh or when you navigate away from the current page, then ngOnDestroy won't be called. The application will just be destroyed by the browser.
ngOnDestroy
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.
destroy()
ngOnDestroy()
You can listen to beforeunload and unload yourself if you need some action to happen before the application is destroyed by the browser.
beforeunload
unload
See also
1.4m articles
1.4m replys
5 comments
56.9k users