I have the MyObject.ts file with the following properties:
name: String
rowStyle: String
In addition, I have a MyComponent.ts file containing:
myObject1: MyObject = new MyObject();
myObject2: MyObject = new MyObject();
myObjectList: MyObject[] = [];
myObject1.name = "Red Color Row";
myObject1.rowStyle = "background-color: red";
myObject2.name = "Bold Font";
myObject2.rowStyle = "font-weight: bold";
myObjectList.push(myObject1);
myObjectList.push(myObject2);
Lastly, in my MyComponent.html file, I have the following structure:
<p-table [value]="myObjectList">
<ng-template pTemplate="header">
<tr>
<th>Name</th>
<th>Styles</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-listObject>
<tr [ngStyle]="{'styles': listObject.rowStyle}">
<td>{{ listObject.name }}</td>
<td>{{ listObject.rowStyle }}</td>
</tr>
</ng-template>
</p-table>
How can I apply the specified styles from the rowStyle property to each row of the table?