I am trying to update the component view after a service call during the ngOnInit life cycle. I subscribe to the service method, and then in the subscribe method iterate through the response to create a ToDo object, where I then drag it to the list. However, after this was done, it turned out that todoList was never updated. Any ideas?
Here is the typescript component code:
export class CanvasComponent implements OnInit{
todo: ToDo;
todoList: ToDo[] = [];
tasks: Task[];
errorMessage: string;
constructor(public taskService: TaskService) {
}
ngOnInit(){
// this.todo = new ToDo(0, 'placeholder', false, 'Please Implement custom components!');
// this.newTodo = new ToDo(0, 'placeZholder', false, 'Please Implement custom components!');
this.taskService.GetAll()
.subscribe(response => {
this.todoList = response;
)
}
.. and my component view prints information with this block:
<div class="row">
<div *ngFor="let todo of todoList">
{{todo.title}}
{{todo.description}}
</div>
</div>
source
share