I am encountering an issue with my event binding on a button, specifically (click)="onStart()"
. The problem arises when the event this.numEmitter
is emitted for the first time in setInterval, after which I receive the error message
ERROR TypeError: Cannot read properties of undefined (reading 'emit')
incNum: number;
timer: number;
@Output() numEmitter: EventEmitter<number> = new EventEmitter();
constructor() {
this.timer = -1;
this.incNum = 0;
}
onStart() {
this.timer = window.setInterval(function () {
this.incNum++;
this.numEmitter.emit(this.incNum);
}, 1000);
}
onStop() {
window.clearInterval(this.timer);
}
I would greatly appreciate it if someone could help me identify and resolve this issue.