quoc bao Pham quoc bao Pham - 17 days ago 85
TypeScript Question

Angular Primeng cannot binding data by customer list

I have a rest api to get data, like as

async getAllTrainingClass(): Promise<void>{
await this.traningClassService.getListTrainingClass().then(data
=>this.listTraining = data);
}


try to show data on html, it's OK:

<p-dataTable [value]="listTraining" [rows]="5" [paginator]="true">
.....
</p-dataTable>


But I try to use the customer array, like as:

listData:MyClass[] = new Array<MyClass>();


and push data

this.listData.push(this.item);


on console.log the listData has 2 item, but when biding to html, data does not display.

<p-dataTable [value]="listData" [rows]="5" [paginator]="true">
.....
</p-dataTable>


please advice me.

Answer Source

Use [immutable]="false"

<p-dataTable [immutable]="false" [value]="listData" [rows]="5" [paginator]="true">

</p-dataTable>