【问题标题】:NgFor Button with router link inside内部带有路由器链接的 NgFor 按钮
【发布时间】:2017-02-03 09:09:01
【问题描述】:

我想问有没有办法做到这一点

<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 },

【问题讨论】:

  • 有什么问题?

标签: angular routes angular2-router


【解决方案1】:

通过使用符号[routerLink] 而不是routerLink,您可以将实例属性传递给值。在您的情况下,它将是:

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

【讨论】:

  • 与{{}} 相同,只要它只是一个字符串值。
猜你喜欢
  • 2022-01-17
  • 2020-01-08
  • 1970-01-01
  • 2014-09-04
  • 1970-01-01
  • 1970-01-01
  • 2021-10-15
  • 2016-10-30
  • 1970-01-01
相关资源
最近更新 更多