Refresh/Reload a view/page in Ionic App

Hi All,

I am looking for a way to refresh my current Ionic view/page automatically every, say, 5 minutes. Is there a way to achieve this?

I guess, I am looking for some kind of “timer” or “scheduler”.

Or can I use one of the life-cycle methods? Like ionViewWillEnter()?

One scenario is:

  • Let’s say I am on a page (a list of things with their statuses) in the app and for some reason stop using the phone. The phone will be locked after set time.

  • After, say, 15 minutes I go back to the phone and get back into the app. Here, it will display me the last page/view I was on before the phone got locked.

  • In this situation, I would like to refresh or reload that page to get the current statuses.

Would appreciate if you could provide some pointers.

Thank you!

As a user, I would hate an app that eats my battery when my phone is asleep. Is it possible to achieve your goal with the Platform’s resume event?

1 Like

with Observable from rxjs you can do very good intervals

import {Observable} from 'rxjs/Rx';
let interval:number = 5000; // 5 seconds
let queueInterval = Observable.interval(interval).timeInterval();
queueInterval.subscribe(() => {
// execute everything what is need for refresh your view.
...
});
1 Like

@rapropos - that’s a nice solution for the scenario in my original post. Thanks!

@fishi - your solution with Observable is also very very useful. Thanks to you too!

I ended up using platform.resume for the part where I wanted to refresh the page after app comes in the foreground after it had gone in the background.

And used Observable solution to refresh the Dashboard page of my app.

Any idea if I should be using Web-Sockets for the above purposes though?

Your valuable inputs will be highly appreciated.

Thanks again for your proposed solutions and prompt response. Appreciated!