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) {}
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.
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.
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);
you can use setInteraval function.
setInterval(function(){
$scope.save();
}, 120000)
you can use setInteraval function to call your function every 120000 milliseconds.
setInterval(function(){
$scope.save();
}, 120000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With