I am creating an exam app so when time is up i needed a view controller to pop to tell the user he has exceeded his time and take him/her to a results page!!
But after unsubscribing from the timer, my function gets into a loop!!!
Please, i need help with this..
My codes below!
minutesDisplay: number = 0;
hoursDisplay: number = 0;
secondsDisplay: number = 0;
sub: Subscription;
showAlert() {
let alert = this.alertCtrl.create({
subTitle: 'Ooops, Time Up! ',
});
alert.present();
this.activity.openModal();
}
ngOnInit() {
this.startTimer();
}
public ngOnDestroy() {
if (this.minutesDisplay == 1){
this.sub.unsubscribe();
}
return true;
}
private startTimer() {
let timer = Observable.timer(1, 1000);
this.sub = timer.subscribe(
t => {
this.ticks = t;
this.secondsDisplay = this.getSeconds(this.ticks);
this.minutesDisplay = this.getMinutes(this.ticks);
this.hoursDisplay = this.getHours(this.ticks);
this.ngOnDestroy();
}
);
this.showAlert();
}