angular – RouterLink数组

前端之家收集整理的这篇文章主要介绍了angular – RouterLink数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个超链接,我需要在Angular 4中建立一个路由器链接.我有很多部分到url,其中一部分是一个数组.我不确定如何将数组拆分为routerlink数组的部分.

拿这个人为的例子:

[routerLink]="['/customers',customerid,orderid,arrayofints,anotherint]"

我希望路由器看起来像customerid = 10,order = 500,arrayofints = [1,2,3],anotherint = 888

"/customers/10/500/1/2/3/888"

我最终得到了类似的东西:

"/customers/10/500;0=1;1=2;2=3/888"

解决方法

对于任何非平凡的事情,我都会在组件代码而不是模板中完成工作.所以在模板中:

[routerLink]="customerRouteFor(anotherint)"

在组件中,您可以使用… spread语法:

customerRouteFor(anotherint: number): (string | number)[] {
  return ['/customers',this.customerid,this.orderid,...this.arrayofints,anotherint];
}

在我看来,这似乎比concat方法更清晰.

猜你在找的Angularjs相关文章