How to call a web service every x seconds?


I have to monitor the state of a device every x seconds.
To do this, I have to call a web service that returns the state of the device periodically.
Which is the smartest way to do this?

The check should be done while the user is using the app.
Should I implement a sort of background service?
Is it possible with Ionic4?

Thank you very much



Use interval to call a web service every x second.

//Interval is use to refresh/timeout page, 10000 = 10s
setInterval(data => {
// this.ReadSMSList();
}, 10000);


I would probably use RxJs’ interval method. This would give me more options for the response than just a standard JS interval call.


Thank you @ChrisGriiffith Chris and @gokujy ,
I think that the first method stops to work if the user changes the page.
However I’ll try both and I’ll let you know the result.
Thank you.