NgFor Button里面有路由器链接

时间:2017-02-03 09:09:02

标签: angular routes angular2-router

我想问一下是否有办法做到这一点

<button *ngFor="let link of links" routerLink="{{link.value}} <<<<  (i want to insert value from array to this
">{{link.Name}}</paper-button>

links = [
{Name:'Menu1' , value:'/Menu1'},
{Name:'Menu2' , value:'/Menu2'},
]

在我的路由器模块中,

{ path: 'Menu1',  component: Menu1Component },
{ path: 'Menu2',  component: Menu2Component },

1 个答案:

答案 0 :(得分:1)

使用表示法[routerLink]代替routerLink,您可以将实例属性传递给值。在你的情况下,它将是:

<button *ngFor="let link of links" [routerLink]="link.value">
    {{link.Name}}
</paper-button>