简体   繁体   中英

ngOnInit is not working when the server send event service used in multiple componenets

I created a service for getting SSE(server send events) from backend(Node). When I use this service in one component it's working as expected. But when I try to use in multiple components at very first time ngoninit triggers and loads the data perfectly. When I navigate to one component to another the ngoninit is not triggering and even the services are also not being called. I hope someone can help on this.

Thanks in advance.

Sounds like your components are not removed from the view and therefore not destroyed. Then ngOnInit will not trigger, because an instance of the component already exists

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