Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  196] [ 4]  / answers: 1 / hits: 26853  / 8 Years ago, thu, november 3, 2016, 12:00:00

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



My code:



  public ngAfterViewInit(): void {
this.authenticate_loop();
}

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


setTimeout is started by ngAfterViewInit 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?


More From » angular

 Answers
9
 private authenticate_loop() {
setInterval (() => {
console.log(Hello from setInterval);
}, 500)
}


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


[#60198] Tuesday, November 1, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;