Update data in a module with Angularjs

Asked

Viewed 155 times

3

I am developing an application with angular and I call a webservice that returns me a JSON and I wanted to know how to update this Json from time to time with angular, someone could give me a help?

1 answer

4


Use the service $interval.

It is equivalent to API window.setInterval, but dedicated to using Angularjs (remember that Angular needs to update the view when the model is changed).

The use of this service is quite simple:

interval = $interval(fn, 1000, 0, true);

Description of parameters:

  1. Command to be executed when in range;
  2. Interval in ms of the shots;
  3. Number of repetitions. Use 0 to infinity (default);
  4. If Angular should call the service $apply when the shot is finished (default).

In the first parameter fn, you should call the Web Service, probably using the service $http.

  • I can pass the function that does this in this parameter fn?

  • Yes. Just be careful that if it needs some parameter, you will have to create a wrapper without parameters, or modify the function so that it no longer needs the parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.