AngularJS Timer Services

Posted By : Deepak Mittal | 31-Dec-2014

AngularJS Timer Services

AngularJS has two timer services:-

1. $timeout:-

The $timeout service can be used to call another JS function after a given time delay. The $timeout service only schedules a single call to the function. For repeated calling of a function.To use $timeout service you must inject this in your controller and once the $timeout service is injected into your controller, you can use it to schedule function calls. Here is an example that used the $timeout service to schedule a function call 3 seconds later:

 

var app = angular.module("app", []); 
app.controller("MyController", function($scope, $timeout){ 
$timeout(callingTimeout, 3000); });
function callingTimeout() { 
console.log("Timeout started"); 
}

 

2. $interval:-

 

The $interval service is similar in function to the $timeout service, except it schedules a function for repeated execution with a time interval in between.And to use the $interval service you must have it injected into a controller function. Once the $interval service is injected into your controller function, you can use it to schedule repeated function calls. Here is an example that used the $interval service to schedule a function call every 3 seconds:


 

var app = angular.module("app", []); app.controller("MyController", function($scope, $interval){ $interval(callingInterval, 3000); }); function callingInterval() { console.log("Interval started"); }

 which you can use to call functions in your application. 

 

THANKS

About Author

Author Image
Deepak Mittal

Deepak is a bright web Developer. Deepak has expertise in Java.

Request for Proposal

Name is required

Comment is required

Sending message..