I am calling api to get data on ngOnInit. However I am not able to assign the data class variable. Below is the related code
tasks: Task[];
ngOnInit() {
this.apiService.getTasks()
.subscribe( data => {
Object.keys(data).map((index) => {
this.tasks.push(data[index]);
});
});
}
I get error saying 'TypeError: Cannot read property 'push' of undefined' for statement
this.tasks.push(data[index]);
But the tasks is already defined as array.
Can anyone help me here, the scope really confuses me
tasks: Task[] = []