I am working with an array that is fetching data from a JSON file. I have successfully stored an array of objects into my Task[]
. Now, my goal is to retrieve the data based on their status ('Submitted' or 'Resolved' etc). Despite trying various methods, I have been unsuccessful in achieving this. Any assistance would be greatly appreciated.
data: [{
taskname: 'Test1',
taskId: '1',
status: 'Submitted'
}, {
taskname: 'Test2',
taskId: '2',
status: 'Resolved'
}, {
taskname: 'Test3',
taskId: '4',
status: 'Submitted'
}, {
taskname: 'Test4',
taskId: '5',
status: 'In Progress'
}, {
taskname: 'Test5',
taskId: '6',
status: 'Resolved'
}, {
taskname: 'Test6',
taskId: '7',
status: 'Submitted'
}
}]
Task.ts
export interface Task {
taskId: any;
taskname: any;
status: any;
}
taskService.ts
getTask() {
return this.http.get('../app/common/task.json')
.toPromise()
.then(res => < Task[] > res.json().data)
.then(data => {
return data;
});
}
taskCompnent.ts
export class TaskComponent implements OnInit {
taskList: Task[];
datasource: Task[];
sortedList: Task[];
ngOnInit() {
this.taskService.getTask().then(files => this.files = files);
this.vecService.getData().then(taskList => {
this.datasource = taskList;
this.taskList = this.datasource; // Storing data into my task list array
});
}
}
This is how I attempted to filter by status:
this.sortedList = this.taskList.filter(
task => task.status ==='Submitted');
An error is being displayed below:
Cannot read property 'filter' of undefined