如何解决在动态角度表上应用日期管道
我的“数据”对象看起来像
[
{"id": "abc001","lastInspectionDate": "2019-09-26T00:00:00.000Z","nextInspectionDate": "2021-09-26T00:00:00.000Z"},{"id": "abc002","lastInspectionDate":"2018-08-25T00:00:00.000Z","nextInspectionDate": "2020-08-25T00:00:00.000Z"}
]
我想在动态表中显示数据。下面是我的HTML代码。
<table mat-table [dataSource]="dataSource" class="mt-2 mat-elevation-z0">
<ng-container *ngFor="let column of allCols" [matColumnDef]="column">
<th mat-header-cell *matHeaderCellDef>{{ column }}</th>
<td mat-cell *matCellDef="let row">
{{ column['lastInspectionDate'] ? (row[column]| date: 'mediumDate') : row[column] }}
</td>
</ng-container>
</table>
这是我的ts代码,用于定义表格的数据源。
this.dataSource.data = data;
this.pageSize = data.length;
let headers = Object.keys(data[0]);
this.allCols = headers;
我的日期条件管道不起作用。你们可以帮我还是给我另一种解决方案?我已经坚持了一个星期。非常感谢您的帮助。
解决方法
也许您应该尝试以下方法:
<table mat-table [dataSource]="dataSource" class="mt-2 mat-elevation-z0">
<ng-container *ngFor="let column of allCols" [matColumnDef]="column">
<th mat-header-cell *matHeaderCellDef>{{ column }}</th>
<td mat-cell *matCellDef="let row">
{{ column === 'lastInspectionDate' ? (row[column]| date: 'mediumDate') : row[column] }}
</td>
</ng-container>
</table>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。