I have a table component listing users with a link to redirect to another component in order to edit the record. From table component I call the details component where I want to call a service to fetch me user record. Although I pass the id parameter properly, I am not sure what is the proper way to read it from the details component.
table component:
<tbody>
<tr *ngFor="let user of users">
<td><a routerLink="/users/details/{{user.id}}">{{user.name}}</a></td>
<td>{{user.Name}}</td>
</tr>
</tbody>
register router in AppModule:
{ path: 'users/details/:id', component: DisplayUserComponent }
and here is how I plan to call the service from the details component:
export class DisplayUserComponent {
constructor(private userService: UserService) { }
ngOnInit() {
this.userService.getUserById(???????USER_ID????????)
.subscribe(res => console.log(res));
}
}
Again, my question is how to get user id from the component which is passed through routing. Any help is welcome!