Have to manual reload page to get data

I am using a service to fetch the products from woocommerce. In the constructor of the service, I make an HTTP get call which fetches products and subscribe to the local data variable.Then I created a function getData() in the service which returns this fetched data to myPage. Then from myPage, I make a call to the getData() function from the constructor of my Component page and assign it to the local products array.
The problem is that when my page gets loaded initially the data is not yet received/subscribed by the HTTP get call inside my service constructor so the getData() function call returns null array and I have to reload the component page manually after the data have been received in the service to get the data in my page.

Any idea what I am doing wrong here? and possible solution for that.
Thanks

Hi testionic121,

You can try this for Reloading current Page,
this.navCtrl.setRoot(this.navCtrl.getActive().component);

Hey, thanks for the reply. Is there any solution in which page only gets loaded when the data is received?

You can write that reloading code in the finally function.
.finally(() => { this.navCtrl.setRoot(this.navCtrl.getActive().component); });

2 Likes

ok. i will do that.
Thanks mate.

1 Like