Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Adding routerLink parameters to chosen table value

I have a routerLink attached to the lead value in a table I have created in the HTML of an angular2 component. Upon clicking that table value, I want the routerLink to not only send to the next component but also bring the chosen value to the next component.

Example of current code

<a [routerLink]="['/Records']" ><td> {{Member.Name}} <td></a>

I have the link so it is sending to the Records page, however how do I send the name to that component so that I can display the specific record that I am trying to display?

like image 489
Matt Fazzini Avatar asked Feb 27 '17 20:02

Matt Fazzini


1 Answers

Add a route parameter to the url and then access that value using the ActivatedRoute.

Route Definition
{ path: "Records/:name", component: RecordsComponent }
Link
<a [routerLink]="['/Records', Member.Name]" ><td> {{Member.Name}} <td></a>
Get Value
@Component({
    ...
})
export class RecordsComponent implements OnInit {

    constructor(private _route: ActivatedRoute) { }

    ngOnInit(){
        this._route.params.subscribe((params) => {
        var recordName = params["name"];
        //load record data
   });
}
like image 161
Teddy Sterne Avatar answered Sep 22 '22 15:09

Teddy Sterne