I want to execute function in angular on a specific time interval and how can we stop that too. Please give me solution for that.
Asked
Active
Viewed 500 times
-2
-
Please show us what you've tried so far. What have you found in your research? – Kurt Hamilton Mar 11 '20 at 11:33
-
https://stackoverflow.com/help/how-to-ask – Kurt Hamilton Mar 11 '20 at 11:35
-
Does this answer your question? [Run JavaScript function at regular time interval](https://stackoverflow.com/questions/18070659/run-javascript-function-at-regular-time-interval) – Ms.Tamil Mar 11 '20 at 11:41
1 Answers
2
Your question seems to be about JavaScript in general, not specifically Angular.
You could use setInterval
and clearInterval
to execute a function on a fixed interval:
// Will print each second
let interval = setInterval(() => console.log("I am a text"), 1000)
// Stops the interval
clearInterval(interval)
Documentation: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

Numbnut
- 106
- 1
- 5