The excellent PrimeNG documentation provides a clear example of this concept. For instance:
<p-table [value]="cars">
<ng-template pTemplate="header">
<tr>
<th *ngFor="let col of cols">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td *ngFor="let col of cols">
{{car[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
This code snippet clearly demonstrates the usage of the body and header templates marked with the pTemplate
Directive.
The p-table
component can easily locate and utilize these templates through ng-container
in combination with the structural Directive ngTemplateOutlet
.
If you're interested, you can access the source code here.
@ContentChildren(PrimeTemplate) templates: QueryList<PrimeTemplate>;