I\'m trying to create a Timer that calls an API call every 10 seconds, I\'m using setTimeOut but the thing is that it becomes an infin
Use observable.timer for your purpose in angular way.
export class CurrentRunsComponent implements OnInit, OnDestroy {
private timer;
ngOnInit() {
this.timer = Observable.timer(10000);
this.timer.subscribe((t) => this.onTimeOut());
}
onTimeOut() {
this.ApiCall().then(
success => {
if(success ['ok'] == 0){
this.navCtrl.push(myPage);
}
},
error => { console.log(error); });
}
ngOnDestroy(){
console.log("Destroy timer");
}
}