Setting up the Activated Route to Update a Course
Explore how to use Angular's ActivatedRoute to fetch and prefill course data for editing. Understand routing setup, form configuration with FormBuilder, and consuming REST APIs to update courses.
Configuring the ActivatedRoute
The ActivatedRoute is an API that holds observable data about a route related to a component loaded in an outlet. To implement ActivatedRoute, we follow the steps below:
Step 1: Implement routing and navigation
We start by opening the course-list.component.html file, and then in the edit icon tag, we create a click event handler called editCourse(), which contains a parameter of the courseId. In the code widget below, we have the (click) event handler that contains the editCourse function in line 30.
Step 2: Router configuration
To configure the router, we need to head to our course-list.component.ts file and implement the code below:
Below is a summary of the code in the widget above:
- We import
Routerin line 2. We then inject it inside theconstructorin line 12. - In