NNi*_*lov 5 typescript primeng angular
我想将 primeng Turbo Table 组件包装在我自己的组件中,但无法弄清楚如何在我传递给我的自定义组件的模板中使用 primeng pSortIcon 和 pSortableColumn 指令。
<my-table #tableCmp
[value]="val"
[columns]="columns"
sortMode="multiple"
[responsive]="true"
[paginator]="true"
[rows]="10"
[lazy]="true"
[totalRecords]="totalRecordsLen"
[pageLinks]="3"
(onLazyLoading)="lazyLoadData($event)"
(onSort)="onSort($event)">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field">
{{col.header}}
<p-sortIcon [field]="col.field"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</my-table>
Run Code Online (Sandbox Code Playgroud)
这就是我将模板应用于我的自定义组件的方式:
@ContentChildren(PrimeTemplate) tpl: QueryList<PrimeTemplate>;
ngAfterContentInit() {
const originalTableNgAfterContentInit = this.table.ngAfterContentInit;
this.table.ngAfterContentInit = () => {
this.table.tpl= this.tpl;
originalTableNgAfterContentInit.call(this.table);
};
}
Run Code Online (Sandbox Code Playgroud)
当我使用我的自定义组件时,它给了我以下错误:
p-sortIcon/pSortableColumn 不是已知元素
在我的模块中,我导入了 TableModule,并且检查了 TableModule 导出了 SortIcon 和 SortableColumn。
如果有人知道如何解决我的问题,我将不胜感激!
| 归档时间: |
|
| 查看次数: |
1240 次 |
| 最近记录: |