Using setTimeout()
it is possible to launch a function at a specified time:
setTimeout(function, 60000);
But what if I would l
Call a Javascript function every 2 second continuously for 10 second.
var intervalPromise; $scope.startTimer = function(fn, delay, timeoutTime) { intervalPromise = $interval(function() { fn(); var currentTime = new Date().getTime() - $scope.startTime; if (currentTime > timeoutTime){ $interval.cancel(intervalPromise); } }, delay); }; $scope.startTimer(hello, 2000, 10000); hello(){ console.log("hello"); }