In AngularJS, $ interval is used to handle intermittent tasks. Next, we will introduce the usage of $ interval in AngularJS through this article, for more information, see $ interval in AngularJS.
The most common ones are:
var app = angular.module("app",[]);app.controller("AppCtrl", function($q. $interval){var timer = $interval(function(){},100);timer.then(success);function success(){console.log("done");}})
In the preceding example, we do one thing every 100 milliseconds, and all of them call the then function last night. That is, $ interval provides the callback function.
Can I control the number of tasks?
-- Yes. Var timer = $ interval (function () {}, 100,10 );
Above, the last real parameter 10 is the limit of the number of times.
In addition to calling after all events, what other callback functions does the callback function have?
-- Some also include the callback function for each event call and the callback function for the error.
Var timer = $ interval (function () {}, 100, 10); timer. then (success, error, policy); function success () {console. log ("done");} function error () {console. log ("error");} function running y () {console. log ("update every time ");}
Can I cancel the $ interval service?
-- Use $ interval. cancle (timer); var timer = $ interval (function () {}, 100, 10); this. cancel = function () {$ interval. cancel (timer );}
The above is a detailed description of the $ interval usage in AngularJS. I hope it will be helpful to you.