【发布时间】:2021-01-09 04:01:25
【问题描述】:
我有以下垫表,每条记录都有编辑和删除按钮:
Name | Operation |
-------|-----------------|
Bob | Edit | Delete |
John | Edit | Delete |
Willy | Edit | Delete |
我使用的mat-table结构如下图:
<ng-container matColumnDef="operation">
<th mat-header-cell *matHeaderCellDef>Operation</th>
<td mat-cell *matCellDef="let row">
<ng-container *ngFor="let operation of operations">
<button [disabled]="row.isActive">
<mat-icon>{{ operation.icon }}</mat-icon>
</button>
</ng-container>
</td>
</ng-container>
我想通过从父组件发送参数(“operation.isDisabled”)并在每一行中使用列值(“row.isActive”)来启用/禁用删除按钮。但是,由于它是基表,我不想使用特定值并尝试通过“操作”变量(如 operation.condition = "row.isActive && operation.type === 'delete '”。但不幸的是我无法通过以下配置做到这一点(我可以通过配置,没有问题。但我需要在if条件下进行):
this.operation = [
{
type: 'delete',
condition: 'row.isActive && operation.type === "delete"'
}
];
那么,是否可以使用从父组件发送的这两个条件作为字符串等操作单个按钮?
【问题讨论】:
标签: javascript angular typescript angular-material mat-table