Angularjs Examples

AJS Examples


AngularJS $interval Service

The AngularJS $interval service is similar to JavaScript's window.setInterval function. In angular it is refer to it through the $interval service. The $interval is just wrapper for window.setInterval function so that it will be easy to override, remove or mocked for testing.

The $interval service is executed provided function on every delay milliseconds.

Syntax

AngularJS $interval Service Example 1

Specify Count

The $interval service also allows to specify the count parameter. The specified function executes number of times as count parameter.

Syntax

AngularJS $interval Service Example 2

Cancel Execution

The $interval service returns a promise which will be notified on each iteration, which can be used to stop or cancel the task by using $interval.cancel(promise) method.

Syntax

AngularJS $interval Service Example 3