After successfully retrieving tasks from the API and confirming that the data is accurate, I encountered an issue when trying to log it in the console as it returned undefined.
Below is my code:
tasksEvents: Task[];
getTasks() {
this._taskService.getTasks()
.subscribe(
res => { this.tasksEvents = res },
err => console.error(err)
)
}
ngOnInit(): void {
this.getTasks();
console.log(this.getTasks(); <------ Undefined
}
Although the data retrieval is working fine, I am looking for ways to further utilize the getTasks()
function.
Here is the relevant snippet from task.service.ts
:
taskUrl = 'http://127.0.0.1:8000/api/tasks';
getTasks() {
return this._http.get<Task[]>(this.taskUrl);
}