You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- In this section will learn to pass and read route parameters, as given below:
410
+
-http://localhost:4200/departments/production
411
+
-http://localhost:4200/user/1
412
+
-http://localhost:4200/employee/100
413
+
1. In `app-routing.module.ts` create `departments/:id` path route parameters for items under department list component
414
+
2. In `department-list.component.ts` class file create a array of departments object
415
+
3. In `department-list.component.html` view file iterate/*ngFor through departments array and pass departments id as a route parameter
416
+
- on click of the department list item, it will take to `department-details.component page with selected department id`, at the same time browser location path will be displayed as `localhost:5000/department:2 (selected department id )`
417
+
- To navigate from code/links/buttons we need `router service as a dependency`
418
+
4. Create and use a new component to show details: `department-details.component.ts` - read the departments id passed as a parameter and show the route view accordingly
419
+
-`activatedRoute.snapshot.paramMap.get()` is used to read the routes/parameters passed
<h3>Selected Deparment Details ID : {{ selectedDepartmentId }} </h3>
545
+
```
546
+
547
+
<p>
548
+
<figure>
549
+
<img src="./_images-angular-routing/3.1-route-parameters-department-list-home.png" alt="Image - Output - Route P arameters Department List" title="Image - Output - Route P arameters Department List width="1000" border="2" />
550
+
<figcaption> Image - Output - Route P arameters Department List</figcaption>
551
+
</figure>
552
+
</p>
553
+
554
+
<p>
555
+
<figure>
556
+
<img src="./_images-angular-routing/3.2-route-parameters-department-clicked.png" alt="Image - Output - Route P arameters Department Clicked/Selected" title="Image - Output - Route P arameters Department Clicked/Selected width="1000" border="2" />
557
+
<figcaption> Image - Output - Route P arameters Department Clicked/Selected</figcaption>
0 commit comments