Reputation: 53
Is it possible to destroy component from serivce? For example call this.component.ngOnDestroy() in service method or something similar?
Upvotes: 0
Views: 3028
Reputation: 8773
No, you can't do that, it's a lifecycle hook that is called when angular destroys the component by itself.
You can use the ngIf
directive in the component and update the value in the directive using service. This is the way you can remove the angular component from DOM and angular destroys it automatically.
Upvotes: 1