简体   繁体   中英

Destroy component from service Angular

Is it possible to destroy component from serivce? For example call this.component.ngOnDestroy() in service method or something similar?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM