2017-05-26 47 views
0

嗨了新的变数,我有以下角4模板代码代码:如何绑定值结合起来,在Angular2/4

<tr *ngFor="let row of rows"> 
    <td> 
     <a [routerLink]="['/test/test1', id1, id2]"> 
      {{row.summary[0].width}} 
      {{row.summary[0].length}} 
      {{row.summary[0].vol}} 
     </a> 
    </td> 
</tr> 

现在我想的URL路径更改为以下:

<a [routerLink]="['/test/test1', item.id1, newID]"> 

新的ID(ID2)必须是

id2 = {{row.summary[0].width}} 
{{row.summary[0].length}} 
{{row.summary[0].vol}} 

组合的价值如何能做到这一点的角?

+0

什么是最后的网址,你可以举个例子。/test/test1?newID = **** –

+0

nope。它应该是'/ test/test1/newID' – blackdaemon

+0

是否像/ test/test1/width/length/vol? –

回答

1

在你的组件只需创建属性:

export class MyComponent implements OnInit { 

    ngOnInit() { } 

    getNewId(sum): string { 
    return `${sum.width}${sum.length}${sum.vol}`; 
    } 
} 

而且在模板中使用:

<td> 
    <a [routerLink]="['/test/test1', getNewId(row.summary[0])]"> 
    {{row.summary[0].width}} 
    {{row.summary[0].length}} 
    {{row.summary[0].vol}} 
    </a> 
</td> 
+0

嗨,实际上我得到的价值来自* ngFor。我无法处理组件中的值 – blackdaemon

+0

实际上,您可以创建接受行摘要并返回'newId'的组件方法 – neilhem

相关问题