I have a typescript class where I am encountering some issues with accessing the starttime and count in the setInterval function. Even though I have set their values before, I am seeing undefined and NaN results. How can I resolve this problem?
startTimer() {
this.startTime = new Date();
this.count = 100;
console.log("STARTTIME: " + this.startTime); //RESULT: Mon Dec 17..etc
console.log("COUNT: " + this.count); //RESULT: 100
this.timer = setInterval(function () {
console.log("STARTTIME: " + this.startTime); //Undefined
this.count += 1;
console.log("COUNT: " + this.count); //NaN
}, 1000);
}