intervalID: number;
value: number=0;
startGame(){
console.log("gameStarted");
this.intervalID=window.setInterval(this.currentNumber,2000);
}
currentNumber(){
console.log("in current number");
console.log(this.value);//**Here i am getting undefined**
this.value++;
console.log(this.value);// **here i am getting NaN**
this.numberGenerated.emit({currentValue:this.value});
}
在currentNumber中使用值时,我得到了未定义。因此,对价值进行的任何操作都会导致NaN
答案 0 :(得分:2)
更改:
this.intervalID=window.setInterval(this.currentNumber,2000);
致:
this.intervalID=window.setInterval(() => this.currentNumber(),2000);