Angular2 – 将routerLink参数添加到选定的表值

前端之家收集整理的这篇文章主要介绍了Angular2 – 将routerLink参数添加到选定的表值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个routerLink附加到我在angular2组件的 HTML中创建的表中的前导值.单击该表值后,我希望routerLink不仅可以发送到下一个组件,还可以将所选值带到下一个组件.

当前代码示例

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

我有链接,所以它发送到记录页面,但是如何将名称发送到该组件,以便我可以显示我试图显示的特定记录?

解决方法

将路由参数添加到URL,然后使用ActivatedRoute访问该值.

路线定义

{ path: "Records/:name",component: RecordsComponent }

链接

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

获得价值

@Component({
    ...
})
export class RecordsComponent implements OnInit {

    constructor(private _route: ActivatedRoute) { }

    ngOnInit(){
        this._route.params.subscribe((params) => {
        var recordName = params["name"];
        //load record data
   });
}

猜你在找的Angularjs相关文章