Having recently delved into Angular 2, I find myself facing a challenge with accessing the "task_title" within the startTimer() function. The console.log() returns undefined and I suspect it's due to "this" referring to the function itself instead of the value of "task_title".
Is there a way in Typescript to access a global variable within a nested function?
export class DashboardComponent {
task_title: string;
myTimer = setTimeout(this.startTimer, 2000);
updateTask(event: any){
clearTimeout(this.myTimer);
this.task_title = event.target.value;
this.myTimer = setTimeout(this.startTimer, 2000);
}
startTimer() {
console.log(this.task_title);
this.myTimer = setTimeout(this.startTimer, 2000);
};
}
Outcome: Undefined.