Reputation: 543
I have a Home Page, inside that I have created one component RecentlyViewedProductComponent
.
My problem is:
when I navigate to /home
by using
this.router.navigate(['/home']);
the ngOnInit()
inside RecentlyViewedProductComponent
is not working. When I close the app and open it again, that only it is working .
How to solve this problem?
Upvotes: 2
Views: 252
Reputation: 13125
It sounds like you are not using the right lifecycle event.
Have you looked at the documentation here:
It says that ngOnInit()
is:
Fired once during component initialization. This event can be used to initialize local members and make calls into services that only need to be done once.
If you want it to be called every time you navigate to the home page then you want to replace this with something like ionViewWillEnter()
:
Fired when the component routing to is about to animate into view.
There is actually some guidance at the end of the docs page that you might find interesting which explains when to use each life cycle method.
Upvotes: 2