나는 파이프를 사용하여 각도로 데이터를 포맷하려고합니다. 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>
편집 : 난 그냥에 시도 {{트란 [col.field] + col.type}}에 오류가 없으면 내 데이터 유형 이름이 값과 함께 표시됩니다. 문제가 발생하면 | 당신이 데이터에 의해 파이프를 제공하려면 중간에 ..
는
왜 파이프에 전체'col' 개체를 전달하지 작동? 그렇다면 거기에 타입 체크를해라. – Sasxa
내가 어떻게 그걸 할 수 있는지 알고 싶다. 작은 샘플을 주시겠습니까? – Ezi
다음은 파이프에 객체를 전달하는 예입니다. [plunker] (http://plnkr.co/edit/l5AVp7TqI2vnjt7yDTxe?p=preview) – Sasxa