因此,我的应用程序中有一个组件,它包装了MatTable
组件,并为我的所有表添加了一些通用功能(例如加载指示器等)
我通过以下方式使用此表
<ngx-progress-table ...>
<ng-content matColumnDef="someColumn">
...
</ng-content>
</ngx-progress-table>
NgxProgressTableComponent
中的实现是
<mat-table ...>
...
<mat-header-row />
<mat-row />
</mat-table>
然后在组件中添加以下列:
ngAfterContentInit() {
this.columnDefs.forEach(columnDef => this.table.addColumnDef(columnDef));
}
这很好用,但是我现在需要使用MatSort
向表中添加排序功能。我已经在组件中的表声明中添加了matSort
,但是在列def中添加了mat-sort-header
时,出现了以下错误MatSortHeader must be placed within a parent element with the MatSort directive
我得到了错误的含义,因为我的列def位于未实现MatSort
的父组件中,但是我找不到任何实现此目的的方法。
这是完全可能的,还是拥有一个完全扩展MatTable
组件的组件会更好?