Search code examples
angularangular-lifecycle-hooks

ngOnDestroy while reloading page


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?


Solution

  • 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