Periodically calling a service with Ionic 4

This forum contains topics that were moved from Get Satisfaction
Joe5648138
Posts: 0
Joined: Sat Apr 25, 2020 2:48 pm

Periodically calling a service with Ionic 4

Post by Joe5648138 »

I'm trying to automatically execute a service every few seconds, I found some code in the forums but it doesn't appear to work with the Ionic 4 app builder.

var $interval = Apperyio.get("$interval");
$scope.myInterval = $interval(function() {
// put your JS code here
}, 100);

How do I access the $interval function with Ionic 4?

Thank you!

Joe5648138
Posts: 0
Joined: Sat Apr 25, 2020 2:48 pm

Periodically calling a service with Ionic 4

Post by Joe5648138 »

I found a solution just in case anyone else has this issue. setInterval seems to work just as well since I couldn't figure out how to call the $interval function.

In the before page action:
this.timer = setInterval(() = {
this.updateTimer();
}, 1000);

In the after page action:
clearInterval(this.timer);

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

Periodically calling a service with Ionic 4

Post by Serhii Kulibaba »

Glad to hear things are sorted out now! Thank you for the update

Post Reply