-1

Anybody know how to refresh the page in the ionic application. My app displays a page after sometime getting updated data from webservice and I want to displays the updated data in that page. So I have to refresh the page to displays updated info.

I tried with location.reload, but no luck also don't want to use setroot. Any other way to accomplish this?

Also don't want to use content.ionviewDidLoad() and all.

Thanks Ak

Ankr
  • 129
  • 2
  • 9
  • have you tried using observables? – Patricio Vargas Jun 25 '18 at 16:08
  • you do not need to refresh the page to reflect the changes Can you share code? – Vikas Jun 25 '18 at 16:08
  • Using observables, we updated the object. But how we display the updated data in the page – Ankr Jun 25 '18 at 16:39
  • you don't need to do anything to update the data in view as long as you have binding to the object which will get the data from service. – RamY Jun 25 '18 at 18:19
  • @Vikas: I can't show the entire code. Also i already mentioned that what are the things I tried to get this work. By the way I didn't ask this question without trying anything from my side, also I knew about idownvotedbecau.se/nocode – Ankr Jun 26 '18 at 04:26
  • I did not ask for entire code Provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Vikas Jun 26 '18 at 04:30
  • @Vikas: Simple, getting data from webservice and store it in **Array of Objects**. When the page is getting open, from ionViewDidEnter() fetch the data from Array and display it in ion-list. Once the page displayed after some time, the timer triggers and again webservice fetch the data and update the **ObjectArray**. But we need to update the list once **Array of object" getting updated. Hope you got the scenario and I can give this much info only from myside. – Ankr Jun 26 '18 at 04:36
  • 1
    Fine Have a Look at [this](https://stackoverflow.com/q/45499982/5695162) – Vikas Jun 26 '18 at 06:12
  • @Vikas: Thanks bro, it is working now and the problem is UI not getting updated on first refresh. It will get updated on second refresh only – Ankr Jun 26 '18 at 11:00

2 Answers2

0

The best way to refresh the page component

this.navCtrl.setRoot(this.navCtrl.getActive().component);
Arjun Ramdas
  • 185
  • 3
  • 13
-1

This works in Ionic too and does the trick:

   location.reload();

Although as mentioned in comments this is not what you would like to do to display asynchronously loaded data in your page template. Have a look at observables, async pipe for a start.

codeVerses
  • 231
  • 1
  • 6
  • 1
    This is a bad solution. He might need to keep state data. Doing this you reload the whole app. – Becario Senior Jun 25 '18 at 16:38
  • The question said nothing about preserving the state data, actually it may suggest he currently does not care about it too much. I also pointed him towards more consistent ways of refreshing data on a webpage. Bests. – codeVerses Jun 25 '18 at 17:23