I get an error when I write this recursive function in Angular 2 (Typescript):
ngOnInit() {
this.countdown(6)
}
countdown(time) {
this.timeLeft = time - 1
console.log(this.timeLeft)
setInterval(function() {
this.countdown(this.timeLeft)
}, 1000)
}
timeLeft is declared as a class property.
Here is the error I get:
EXCEPTION: this.countdown is not a function
What am I doing wrong?
Thanks!