Next, let's look at the use of $interval and $timeout
$interval can be used for timed tasks, we only need to inject $interval in the controller to use it. The following is the alert() function that is executed every ten seconds.
app.controller("ctrl", function($scope,$timeout,$interval) { $interval(function(){ alert("545") },10000); });
We can define the number of times the function is executed, and it will not be executed if it is executed three times as follows
app.controller("ctrl", function($scope,$timeout,$interval) { $scope.exe=$interval(function(){ alert("545") },10000,3); });
We can also terminate the execution of the timer as follows
$interval.cancel($scope.exe)
$timeout is used for lazy loading, which is relatively simple, as follows to delay loading for 1 second;
$timeout(function() { alert("454"); }, 1000);