I am making a timer. I have a variable which holds the value of seconds. If I use onclick() to manually minus one from the variable, it works. However, when I run the function through setInterval, it returns NaN.
I have tried adding a '+' before the variable when changing the value, and also tried the Number() function, but to no avail.
export class CountdownPage implements OnInit {
countdown: any;
tabata: any;
id: any;
set: any;
currentSet: any;
setTest: any;
phaseCountdown: any;
currentPhase: any;
phaseWork: any;
phaseRest: any;
phaseEnd: any;
intervalOne: any;
authState$: Observable<boolean>;
constructor(private Auth: AuthService, public http: HttpClient, private
router: Router, private route: ActivatedRoute) {
this.route.queryParams.subscribe(params => {
if (this.router.getCurrentNavigation().extras.state) {
this.countdown =
this.router.getCurrentNavigation().extras.state.tabataData[0].substring(17, 19);
this.tabata = this.router.getCurrentNavigation().extras.state.tabataData[1];
this.id = this.router.getCurrentNavigation().extras.state.tabataData[2];
console.log(this.countdown);
}
});
}
repeat() {
this.intervalOne = setInterval(this.begin, 1000);
}
begin() {
let first = document.querySelector('#counter');
this.countdown = this.countdown - 1;
Number(this.countdown);
first.innerText = this.countdown;
console.log(this.countdown);
}
For info: this.countdown variable is passed through from a service (I'm using Ionic AngularJS).
I am simply after a number stored in a variable that goes down one in value, every second.
Thanks.