Answers for "how to stop interval when leaving component angular"

0

setinterval in angular 6

ngOnInit() {
  this.battleInit();
  this.id = setInterval(() => {
    this.battleInit(); 
  }, 5000);
}

ngOnDestroy() {
  if (this.id) {
    clearInterval(this.id);
  }
}
Posted by: Guest on June-16-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language