Vingtoft Vingtoft - 10 months ago 161
Javascript Question

Angular2: setTimeout only called once

I'm implementing functionality in Angular2 that requires the use of


My code:

public ngAfterViewInit(): void {

private authenticate_loop() {
setTimeout (() => {
console.log("Hello from setTimeout");
}, 500)

is started by
but the loop is only executed once, eg. "Hello fromsetTimeout" is only printed once.

Question: How can I change the code to make the setTimeout work?

Answer Source
 private authenticate_loop() {
    setInterval (() => {
      console.log("Hello from setInterval");
    }, 500)

setTimeout will run just one time, unless you create another setTimeout.