I have the following method in one component:
ngOnInit() { this.battleInit(); setInterval(() => { this.bat
ngOnInit() { this.battleInit(); this.id = setInterval(() => { this.battleInit(); }, 5000); } ngOnDestroy() { if (this.id) { clearInterval(this.id); } }
this.id is an identifier returned by the setInterval that can be used to cancel the operation using clearInterval.
this.id
setInterval
clearInterval