ngOnInit method is not called

104 views Asked by At

When I navigate to my component after the first time, with router.navigate, the ngOnInit method of the component is not called.

Therefore, the previous data I fetched from API is still there. I need to reset all the variables when I navigate away from the page, so the next time the component is re-built from scratch again.

How can I achieve it?

I tried to google for solutions, I tried to change some code, I unsubscribed inside ngOnDestroy but nothing changed.

1

There are 1 answers

0
U.Aasd On

you can use

this.router.routeReuseStrategy.shouldReuseRoute = () => false;
this.router.onSameUrlNavigation = 'reload';
this.router.navigate(['your link'])