Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a pTemplate in PrimeNG?

I was going through the documentation of PrimeNG 4.3.0 for p-tree here, and came across this example where they are using a pTemplate attribute, but I am unable to understand what it does or how it works.

<p-tree [value]="files">
    <ng-template let-node pTemplate="default">
        <input [(ngModel)]="node.label" type="text" style="width:100%">
    </ng-template>
</p-tree>

Could someone please explain what the purpose of pTemplate is?

like image 311
Rajat Avatar asked Jan 23 '26 12:01

Rajat


1 Answers

The only purpose of this directive is to hold ng-template reference (with some unique key assigned with it). Later inside parent component it is possible to grab the list of pTemplate directives:

@ContentChildren(PrimeTemplate) templates: QueryList<any>;

This list is a pair of string key and TemplateRef value.

This mechanism allows software developers to use multiple ng-templates and inject them to *ngTemplateOutlet directives in parent component.

<p-tree [value]="files">
    <ng-template let-node  pTemplate="picture">
        <img [attrs.src]="picture.path">
    </ng-template>
    <ng-template let-node  pTemplate="default">
        <input [(ngModel)]="node.label" type="text" style="width:100%">
    </ng-template>
</p-tree>
like image 182
Karol T Avatar answered Jan 25 '26 07:01

Karol T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!