2

I'm new in Angular7 and PrimeNG. I don't figured out how to pass table caption as variable:

<p-table [value]="userSrv.items"  [title]="table.title">
        <ng-template pTemplate="caption" let-title>
            {{title}}
        </ng-template>
        <ng-template pTemplate="header">
            <tr>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </ng-template>
        <ng-template pTemplate="body" let-item>
            <tr>
                <td>{{item.fullName}}</td>
                <td>{{item.email}}</td>
            </tr>
        </ng-template>
</p-table>

or how to insert dynamic ngTemplate='caption' (or other template) on ngOnInit component method.

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Bogdan
  • 656
  • 15
  • 25

1 Answers1

1

There's no need to define something like [title]="table.title" or let-title.

You can symply use caption templating this way :

<ng-template pTemplate="caption">
    {{title}}
</ng-template>

See working StackBlitz

Antikhippe
  • 6,316
  • 2
  • 28
  • 43