Bin*_*ala 3 typescript primeng angular
我正在尝试显示动态数量的列,并尝试使用 a<ng-template ...来指定单元格的呈现方式。但在我的数据集中有一些字段属于日期类型。我想使用日期管道格式化该字段。
html文件
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns" [style.width]="col.width">
{{rowData[col.field]| col?.pipe}}
</td>
</tr>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
打字稿文件(在 cols 数组中,我想添加另一个这样的字段。)
this.cols = [
{ field: 'no', header: 'No.', width: '50px',pipe:null },
{ field: 'createdDate', header: 'createdDate', width: '175px', pipe: 'date: \'dd/MM/yyyy\''},
{ field: 'deviceName', header: 'Device Name', width: '150px'}
];
Run Code Online (Sandbox Code Playgroud)
我试过这个,它给了我模板解析错误。
错误错误:未捕获(承诺):错误:模板解析错误:
像这样尝试
this.cols = [
{ field: 'no', header: 'No.', width: '50px',pipe:null },
{ field: 'createdDate', header: 'createdDate', width: '175px', data: true , format: `dd/MM/yyyy`},
{ field: 'deviceName', header: 'Device Name', width: '150px'}
];
Run Code Online (Sandbox Code Playgroud)
模板
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns" [style.width]="col.width">
{{ col.data ? (rowData[col.field]| date : col.format) : rowData[col.field] }}
</td>
</tr>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1224 次 |
| 最近记录: |