TypeError: def.when is not a function in Angular Material Table
TypeError: def.when is not a function in Angular Material Table
我尝试使用 when
谓词通过 colspan (matColumnDef="table-filter"
) 获取额外的行。有趣的是,我在应用程序的其他地方(其他模块)使用了相同的原理,并且它工作正常。
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="table-filter">
<td mat-cell [attr.colspan]="displayedColumns.length" *matCellDef="let data">
Test
</td>
</ng-container>
<ng-container matColumnDef="some-column">
<th mat-header-cell *matHeaderCellDef>
Column-Titel
</th>
<td mat-cell *matCellDef="let data">
{{ data.someField }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let role; columns: displayedColumns;"></tr>
<!-- Extra row with when predicate -->
<tr mat-row *matRowDef="let role; columns: ['table-filter']; when testBoolean;"></tr>
</table>
在这里,我得到 TypeError: def.when is not a function
。当我删除多余的行时,table 工作正常(MatTableModule
当然是导入的)。
有什么想法吗?
material: ^8.0.2
angular: ^8.1.1
...愚蠢的我,5 分钟。发布后我发现我对 when
-predicate 使用了一个布尔值 - 但这需要是一个具有以下签名的函数:
/**
* Function that should return true if this row template should be used for the provided index
* and row data. If left undefined, this row will be considered the default row template to use
* when no other when functions return true for the data.
* For every row, there must be at least one when function that passes or an undefined to default.
*/
when: (index: number, rowData: T) => boolean;
我尝试使用 when
谓词通过 colspan (matColumnDef="table-filter"
) 获取额外的行。有趣的是,我在应用程序的其他地方(其他模块)使用了相同的原理,并且它工作正常。
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="table-filter">
<td mat-cell [attr.colspan]="displayedColumns.length" *matCellDef="let data">
Test
</td>
</ng-container>
<ng-container matColumnDef="some-column">
<th mat-header-cell *matHeaderCellDef>
Column-Titel
</th>
<td mat-cell *matCellDef="let data">
{{ data.someField }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let role; columns: displayedColumns;"></tr>
<!-- Extra row with when predicate -->
<tr mat-row *matRowDef="let role; columns: ['table-filter']; when testBoolean;"></tr>
</table>
在这里,我得到 TypeError: def.when is not a function
。当我删除多余的行时,table 工作正常(MatTableModule
当然是导入的)。
有什么想法吗?
material: ^8.0.2
angular: ^8.1.1
...愚蠢的我,5 分钟。发布后我发现我对 when
-predicate 使用了一个布尔值 - 但这需要是一个具有以下签名的函数:
/**
* Function that should return true if this row template should be used for the provided index
* and row data. If left undefined, this row will be considered the default row template to use
* when no other when functions return true for the data.
* For every row, there must be at least one when function that passes or an undefined to default.
*/
when: (index: number, rowData: T) => boolean;