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.