$ Interval usage in AngularJS, angularjsinterval

Source: Internet
Author: User

$ 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

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.