$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