$ Interval usage in AngularJS, angularjsinterval
In AngularJS, $ interval is used to handle intermittent tasks.
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.
Articles you may be interested in:
- SetInterval and setTimeout methods in Jquery
- When setTimeout () and setInterval () are called and executed in Js
- In JS, setInterval and setTimeout cannot pass functions with parameters.
- Jump effect in 5 seconds (setInterval/SetTimeOut)
- Deep understanding of setTimeout and setInterval
- How to use JavaScript SetInterval and setTimeout
- Summary of setInterval usage in JavaScript