我有一个超链接,我需要在Angular 4中创建一个路由器链接。我有很多指向url的部分,其中一部分是一个数组。我不确定如何将数组自身拆分成路由器链接数组的几个部分。
以这个人为的例子为例:
[routerLink]="['/customers', customerid, orderid, arrayofints, anotherint]"我希望路由器看起来像这样,其中customerid = 10,order = 500,arrayofints = 1,2,3,另一个I= 888
"/customers/10/500/1/2/3/888"我最终得到了类似这样的结果:
"/customers/10/500;0=1;1=2;2=3/888"发布于 2017-07-14 05:51:19
对于任何重要的事情,我都会在组件代码而不是模板中完成工作。因此,在模板中:
[routerLink]="customerRouteFor(anotherint)"在组件中,您可以使用...spread语法:
customerRouteFor(anotherint: number): (string | number)[] {
return ['/customers', this.customerid, this.orderid, ...this.arrayofints, anotherint];
}在我看来,这似乎比concat方法要干净得多。
发布于 2017-07-14 05:48:58
扁平化参数将为您提供正确的URL
[routerLink]="[].concat.apply([],['/customers', customerid, orderid, arrayofints, anotherint])"https://stackoverflow.com/questions/45090939
复制相似问题