Angular2: setTimeout only called once
private authenticate_loop() { setInterval (() => { console.log("Hello from setInterval"); }, 500) }
setTimeout
will run just one time, unless you create another setTimeout
.
Edit: So to be more specific for the different angular versions:
In Angular2 you are not required to use $timeout / $interval any more. So for the question here setInterval is the correct solution.
For any one interested in the original response (targeted to Angular1) read the following:
Use $interval inside an angular.js application.
And if you want to use setTimeout somewhere else inside an angular.js application you should better use the $timeout service.
$timeout and $interval have the advantage, that they keep your scope updated, which setTimeout / setInterval do not.