Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call function every 2 mins

Tags:

angularjs

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

 $scope.save = function () {
        $http({
        url : '/api/products',
        method : "POST",
         },
        data : $scope.product,          
    }).success(function (data) {}
like image 295
HD.. Avatar asked Jan 21 '14 07:01

HD..


People also ask

How do you call a function repeatedly?

Answer: Use the JavaScript setInterval() method You can use the JavaScript setInterval() method to execute a function repeatedly after a certain time period. The setInterval() method requires two parameters first one is typically a function or an expression and the other is time delay in milliseconds.

How many times a function is called?

To count how many times a function has been called, declare a count variable outside of the function, setting it to 0 . Inside of the body of the function reassign the variable incrementing it by 1 . The count variable will store the number of function invocations.

How do you call a function after some time in react?

The setTimeout method allows us to run a function once after the interval of the time. Here we have defined a function to log something in the browser console after 2 seconds. const timerId = setTimeout(() => { console. log('Will be called after 2 seconds'); }, 2000);


2 Answers

you can use setInteraval function.

 setInterval(function(){
 $scope.save();
 }, 120000)
like image 178
Madhusanka Edirimanna Avatar answered Oct 04 '22 18:10

Madhusanka Edirimanna


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

setInterval(function(){
  $scope.save();
}, 120000)
like image 26
IgorCh Avatar answered Oct 04 '22 18:10

IgorCh