Submit update form
- ✔️Submit form updateLearn how to submit an update form in an Angular application.
Update the task with the TaskService
The TaskService service already includes a function to add a new task to the list. Let’s add a new function to update an existing task of the list.
🎓 Instructions
-
Update the
src/app/task-service.ts
file.
Update the TaskFormComponent
The TaskFormComponent component is currently used to add a new task to the list.
Let’s handle the submission of the form to update and not create a new task. To do so, keep the same submit function but update it to use the updateTask function of the TaskService service.
When?
- If the task has an id, call the updateTask function.
- If the task doesn’t have an id, call the addTask function.
In both situations, navigate back to the list of tasks.
🎓 Instructions
-
Update the
src/app/task-form/task-form.component.ts
file.
Let’s test it out
- Click on the ‘Update’ button next to a task in the list.
- Update the form with the new task details.
- Click on the ‘Update task’ button.
- The task should be updated in the list.
✔️ What you learned
In this chapter, you learned how to update the TaskFormComponent to handle both updating and creating tasks.