Angularjs The notation of the polling device

Source: Internet
Author: User


$interval

$interval is an encapsulation of the native setInterval , which automatically executes ' $apply ' after each method call
The API is this:

1
$interval (FN, delay, [count], [invokeapply], [Pass]);

FN is the target method

Delay is the latency time, in milliseconds

Count is the total number of cycles

Invokeapply refers to whether the $apply method is called, by default True

Pass is a parameter that the method runs as a pass-through

    • Rewriting the start code of an article

1
2
3
4
5
6
7
8
9
10
11
App.controller (' Datactrl ',function ( $scope, $http, $filter) {
$scope. Process = 0;
$scope. Visible = false;
var p = $interval ( function ( if ($scope. Process >= 100) {
$scope. Visible = false;
500);
//$interval. Cancel (p); Remove
   //some code
}

Add the following code to the controller

var stop;

$scope. $on (' $ionicView. Beforeleave ', function () {

$interval. Cancel;//stop polling after leaving the page

})

Polling

Stop = $interval (function () {

$http. Get ('/staffmessage/staffmessagelist?pageindex=1&pagesize=10 ')

. Success (function (result) {

$scope. data = result;

}). Finally (function () {});

}, 6000);

Inject a bit of code into the controller:

End of the website address (may want to FQ): https://docs.angularjs.org/api/ng/service/$interval

Angularjs The notation of the polling device

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.