Reputation: 807
I'm trying to understand and experiment with Angular lifecycle hooks.
Regarding ngOnDestroy
, in the official documentation it says:
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur when the instance is destroyed.
So, I'm able to trigger the ngOnDestroy
event when I redirect page. Strangely I am unable to trigger ngOnDestroy
when I reload the page. Is it not going to destroy my directives, services when I reload the page? Why is ngOnDestroy
not triggered on page reload?
Upvotes: 2
Views: 2694
Reputation: 5640
ngOnDestroy only gets fired when the component or service is destroyed inside the angular workflow. So, reloading or refreshing the page is out of the scope and hence this method does not fire.
Upvotes: 3
Reputation: 2220
The question has already been answered here:
ngOnDestroy
only fires when the component is destroyed inside the angular workflow. However, refreshing the page is outside of the workflow
Upvotes: 5