[英]Angular 2 (v6) inline if else?
I use Angular Material Tables. 我使用角材料表。 And display in a table a list of columns (displayedColumns).
并在表中显示列列表(displayedColumns)。
I need to display the "birthday" column using the "date" filter ( {{element[column] | date}}
), but let other columns as is. 我需要使用“日期”过滤器(
{{element[column] | date}}
)来显示“生日”列,但让其他列保持原样。 How do I say, if the column=="birthday" then apply the filter "date"? 我怎么说,如果column ==“ birthday”,然后应用过滤器“ date”?
<ng-container matColumnDef="{{column}}" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container>
Try that : 尝试:
<ng-container matColumnDef="{{column}}" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{column === 'birthday' ? (element[column] | date) : element[column]}} </td>
</ng-container>
您可以创建自己的管道来检查column
并适当显示element
,也可以只进行三元检查:
{{column !== "birthday" ? element[column] : element[column] | date}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.