【发布时间】:2019-09-28 11:19:48
【问题描述】:
我试图了解 PrimeNG 中的表格组件是如何工作的。我对如何将父组件的实例传递给子组件的构造函数感到困惑。
这里是 TableBody 组件的源代码,其中包含 Table 组件的一个实例。 PrimeNG Table Source
所以我的理解是 TableBody 组件有一个属性作为选择器。它是从父 (Table) 组件的列和 bodyTemplate 中传递的。现在我不明白的是,父组件(Table)的实例在创建时是如何传递给它的。
表格组件模板片段
<div class="ui-table-wrapper" *ngIf="!scrollable">
<table #table [ngClass]="tableStyleClass" [ngStyle]="tableStyle">
<ng-container *ngTemplateOutlet="colGroupTemplate; context {$implicit: columns}"></ng-container>
<thead class="ui-table-thead">
<ng-container *ngTemplateOutlet="headerTemplate; context: {$implicit: columns}"></ng-container>
</thead>
<tfoot *ngIf="footerTemplate" class="ui-table-tfoot">
<ng-container *ngTemplateOutlet="footerTemplate; context {$implicit: columns}"></ng-container>
</tfoot>
<tbody class="ui-table-tbody" [pTableBody]="columns" [pTableBodyTemplate]="bodyTemplate"></tbody>
</table>
</div>
完整来源:Github source
非常感谢任何见解。
【问题讨论】:
标签: javascript html angular typescript primeng