不能将角度“ PriceRuleApi”分配给类型“ unknown []”。错误this.dataSource.data上的错误点“ PriceRuleApi”无法分配给类型“ unknown []”。有想法吗?
export interface PriceRuleApi {
pricerule: any;
success: boolean,
data: PriceRule[],
total: number,
pageSize: number,
page: number
}
dataSource = new MatTableDataSource();
{_id: "5d9564c336651b0f50bf3e66", name: "Rule 1", __v: 0, books: Array(2)}
map(data => {
this.isLoading = false;
this.isTotalReached = false;
console.log("gg" , data)
// this.totalItems = data
return data;
}),
catchError(() => {
this.isLoading = false;
this.isTotalReached = true;
return observableOf([]);
})
).subscribe(data => this.dataSource.data = data);
export interface PriceRule {
_id: number,
name: string,
books: Array<string>
}
答案 0 :(得分:0)
MatTableDataSource.data
需要一个数组,但似乎您拥有的data
变量只是一个PriceRuleApi
。也许应该是PriceRuleApi[]
或PriceRule[]
,无论您要显示的行所对应的数据是什么
MatTableDataSource
实际上是一个行数组,因此它希望您的数据是这些行的集合。