import {DeferModule} from 'primeng/defer';
Defer is applied to a container element with pDefer directive where content needs to be placed inside an ng-template.
<div pDefer>
<ng-template>
deferred content
</ng-template>
</div>
onLoad callback is useful to initialize the content when it becomes visible on scroll such as loading data.
<div pDefer (onLoad)="initData()">
<ng-template>
<p-dataTable [value]="cars">
<p-column field="vin" header="Vin"></p-column>
<p-column field="year" header="Year"></p-column>
<p-column field="brand" header="Brand"></p-column>
<p-column field="color" header="Color"></p-column>
</p-dataTable>
</ng-template>
</div>
this.cars = //initialize
Directive has no attributes.
| Name | Parameters | Description |
|---|---|---|
| onLoad | - | Callback to invoke when deferred content is loaded. |
Directive does not apply any styling to host.
None.
<div pDefer (onLoad)="initData()">
<ng-template>
<p-dataTable [value]="cars">
<p-column field="vin" header="Vin"></p-column>
<p-column field="year" header="Year"></p-column>
<p-column field="brand" header="Brand"></p-column>
<p-column field="color" header="Color"></p-column>
</p-dataTable>
</ng-template>
</div>
export class DeferDemo {
cars: Car[];
msgs: Message[] = [];
constructor(private carService: CarService) {}
initData() {
this.msgs = [{severity:'success', summary:'Data Initialized', detail:'Render Completed'}];
this.carService.getCarsSmall().then(cars => this.cars = cars);
}
}