how to call function every 2 mins


how to call a save function every two mins in anular js. please Help me.

 $ = function () {
        url : '/api/products',
        method : "POST",
        data : $scope.product,          
    }).success(function (data) {}
Problem courtesy of: HD..


you can use setInteraval function to call your function every 120000 milliseconds.

}, 120000)
Solution courtesy of: IgorCh


You can try the following way also.

Declaring the interval:

var interval = null;

To cancel interval:

if (interval != null)


Call the function as per as interval:

$interval(function() {
}, 120000);
Discussion courtesy of: Chiru Adi

You could try using the $interval service.

In case you need something more accurate, consider using an external library.

Discussion courtesy of: Juho Vepsäläinen

You can use $interval from angularjs

}, 120000)
Discussion courtesy of: user1572225

This recipe can be found in it's original form on Stack Over Flow.