我有一张垫子桌子
< mat-table #table [dataSource] =“orders”[trackBy] =“$ index”>
< ng-container matColumnDef =“id”> < mat-header-cell * matHeaderCellDef> ID< / mat-header -…
您可能必须在拼接后手动触发changedetetor
if (index > -1) { // update at same position this.orders.splice(index, 1, order); this.changeDetectorRefs.detectChanges(); }
从材料 的 CDK 强> 文档和完全在 @Input() dataSource: CdkTableDataSourceInput<T> :
@Input() dataSource: CdkTableDataSourceInput<T>
如果提供了数据数组,则必须在表时通知该表 添加,删除或移动数组的对象。这可以通过 调用renderRows()函数,它将自动渲染diff 最后一个表格。如果数据数组引用已更改,则表格 将自动触发对行的更新。
另外,从JavaScript的角度来看, splice 方法mutate(更改)数组,因此不更改数组引用。
splice
参考: https://material.angular.io/cdk/table/api
你改变了你的元素后 MatTableDataSource 你可以强制你的表重绘
MatTableDataSource
this.order._updateChangeSubscription();