Reputation: 3047
I have a Component showing some kind of a percentagebar and a restapi on a server returning current cpu usage. I want my ionic provider to call the restapi every 10 seconds to update my components view. But I think I didn't really get the concept behind that. Where should I write the loop to do that? In the Provider or in the Component?
Upvotes: 1
Views: 280
Reputation: 910
There are two ways to do this First you can call the provider from the component after every 10 seconds which will provide the component with the data
Second way is that you can call the rest api from the provider after every 10 second and use subject or behaviour subject to tell the component if there are any changes
And the best way will to use observable.interval like this Observable.interval(10000);
If you want to use the second option there is great answer about behavior subject you can check it for reference BehaviorSubject vs Observable?
Upvotes: 1