我正在尝试使用Angular 8并在表中显示数据。显示数据,但即使进行了所有默认更改,排序也不起作用。
MatSortModule添加
客户组件
dataSource = new MatTableDataSource<ICustomer>();
@ViewChild(MatSort,{static:false}) sort: MatSort;
ngOnInit() {
this._customers.getCustomersList().subscribe(data=>{
this.results=data;
this.dataSource=this.results.value;
console.log(this.dataSource);
});
}
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
使用@ViewChild(MatSort, {static: true}) sort: MatSort;
而不是@ViewChild(MatSort, {static: false}) sort: MatSort;
—更改仅设置为static: true
。