Angular 6 run a function in every X seconds

后端 未结 5 1403
我寻月下人不归
我寻月下人不归 2021-01-03 21:53

I have a function called

opensnack(text) { ... };

which is opening an angular material snackbar with the given text input.

What I

5条回答
  •  孤独总比滥情好
    2021-01-03 22:37

    Try to use setInterval

    setInterval will allow to run a function regularly with the interval between the runs

    https://javascript.info/settimeout-setinterval

    Example:

    function opensnack(text: string) : void {
      console.log(text);
    }
    
    setInterval(opensnack, 10000, "my text"); <-- run every 10 second
    

    You can look at this stackblitz example:

提交回复
热议问题