Updating data in a module with AngularJS

3

I'm developing an application with angular and I'm calling a webservice that returns me a JSON and wanted to know how I can update this Json from time to time with angular, could anyone give me a help?

    
asked by anonymous 23.12.2014 / 14:43

1 answer

4

Use the $interval service.

It is equivalent to window.setInterval API, but dedicated to use AngularJS (remember that Angular needs to refresh the view when the model is changed).

The use of this service is quite simple:

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

Parameters description:

  • Command to execute when in range;
  • Interval in ms of shots;
  • Number of repetitions. Use 0 for infinity (default);
  • If Angular should call the $apply service when firing is finished (default).
  • In the first parameter fn , you should call the Web Service, probably using the $http service.

        
    23.12.2014 / 14:52