当我将数据源设置为数组并尝试将dataSource
设置为新的mat表dataSource
以便能够使用过滤时,它会附带错误:
类型'MatTableDataSource'缺少类型'TableRecord []'的以下属性:length,pop,push,concat和另外24个。
但是,如果我将数据源设置为任何数据源,它将正常工作。有人可以帮我了解原因:
service.ts
export interface PaginatedListResponse<TableRecord>{
length: number,
tableRows: Array<TableRecord>
}
export interface TableRecord{
x: string,
y: string,
z: boolean,
}
.ts
dataSource: TableRecord[] = [];
this.dataSource = new MatTableDataSource(response.tableRows);
//errror: Type 'MatTableDataSource<TableRecord>' is missing the following properties from type 'TableRecord[]': length, pop, push, concat, and 24 more.
工作示例
dataSource: any;
this.dataSource = new MatTableDataSource(response.tableRows);
//No error
答案 0 :(得分:1)
数据源的声明错误。这样做:
dataSource: MatTableDataSource<TableRecord> = new MatTableDataSource([]) ;
然后,当您从后端接收数据时:
this.dataSource.data = response.tableRows;