我想用角度使用管道格式化数据。对于标题和字段名称,我使用从typescript传入的数组,它工作得非常好。问题是当我尝试从同一个数组传递字段类型时,角度不接受它。
错误是:
Error: Uncaught (in promise): Template parse errors:
Parser Error: Unexpected token '[' at column 23 in [{{tran[col.field] | tran[col.type]}}] in [email protected]:79
("et tran of _trans"><td class="text-navy" *ngFor="let col of cols">[ERROR ->]
{{tran[col.field] | tran[col.type]}}</td>
打字稿代码:
private cols;
this.cols = [
{ field: "DateCreated", header: "Date", type: "date" },
{ field: "Name", header: "Customer", type: "string" },
{ field: "Amount", header: "Amount", type : "money" }
];
Angular2代码:
<thead>
<tr>
<th *ngFor="let col of cols">{{col.header}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let tran of _trans">
<td class="text-navy"
*ngFor="let col of cols">
{{tran[col.field]
| col.type <--- here's the problem!}}
</td>
</tr>
</tbody>
编辑:我只是试图{{TRAN [col.field] + col.type}}不给出错误,它显示我的数据类型名称和值。问题从我放入|时开始在中间..
为什么不整'col'对象传递给管?然后做类型检查那里... – Sasxa
希望我会知道如何做到这一点......你可以请一个小样本? – Ezi
下面是将对象传递给管道的示例 - [plunker](http://plnkr.co/edit/l5AVp7TqI2vnjt7yDTxe?p=preview) – Sasxa