@Bo
Your conclusion is wrong.
ngOnDestroy is fired BEFORE the directive gets destroyed. As you can read above, its supposed to be used to clean up resources. Nonetheless the directive may not get destroyed for some reason (for example because a reference is holding up to it). But still : it's working as intended => the event is fired because the component is supposed(!) to fade away.
I've read the article again. You open it with
"If we read the OnDestroy lifecycle hook api description Angular OnDestroy we can use it on services."
But, how do you came to that conclusion? The lifecycle is described for components and directives. Where do you read it could be used on sercices?
You may have misunderstood whats written for onDestroy(). Services are mentioned there, right, but its meant as example to use onDestroy on your component to unregister it from(!) services.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
@Bo
Your conclusion is wrong.
ngOnDestroy is fired BEFORE the directive gets destroyed. As you can read above, its supposed to be used to clean up resources. Nonetheless the directive may not get destroyed for some reason (for example because a reference is holding up to it). But still : it's working as intended => the event is fired because the component is supposed(!) to fade away.
My articles is about services so providers and not directives. So the conclusion is for using ngOnDestroy on a service and NOT on a directive
I've read the article again. You open it with
"If we read the OnDestroy lifecycle hook api description Angular OnDestroy we can use it on services."
But, how do you came to that conclusion? The lifecycle is described for components and directives. Where do you read it could be used on sercices?
You may have misunderstood whats written for onDestroy(). Services are mentioned there, right, but its meant as example to use onDestroy on your component to unregister it from(!) services.