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.
- Please show us what you've tried so far. What have you found in your research?Kurt Hamilton– Kurt Hamilton2020-03-11 11:33:57 +00:00Commented Mar 11, 2020 at 11:33
- stackoverflow.com/help/how-to-askKurt Hamilton– Kurt Hamilton2020-03-11 11:35:42 +00:00Commented Mar 11, 2020 at 11:35
- Does this answer your question? Run JavaScript function at regular time intervalMs.Tamil– Ms.Tamil2020-03-11 11:41:00 +00:00Commented Mar 11, 2020 at 11:41
Add a comment |
1 Answer
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