In Angularjs, $interval is used to handle intermittent processing of some things.
The most commonly used 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");
}
Above, do one thing every 100 milliseconds, and all are calling the then function last night. That is, the $interval provides a callback function.
Can you control the number of times you do things?
--It's OK.
var timer = $interval (function () {},100,10);
Above, the last argument 10 is the limit number.
What other callback functions does the callback function have in addition to being invoked at the end of everything?
--Yes, it also includes the callback function each time the event is invoked, and the callback function when the error occurs.
The var timer = $interval (function () {},100);
Timer.then (Success, error, notify);
Function success () {
console.log ("Done");
}
Function error () {
console.log ("error");
}
function Notify () {
console.log ("Update every Time");
}
Is it possible to cancel the $interval service?
--through $interval.cancle (timer);
The var timer = $interval (function () {},100);
This.cancel = function () {
$interval. Cancel (timer);
The above is aimed at the use of $interval in Angularjs to do the detailed, I hope to help you.