The usage of $interval in Angularjs _angularjs

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.