我有MyObject.ts文件作为
name:String
rowStyle:String
和MyComponent.ts文件作为
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);
和MyComponent.html文件作为
<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>
<td>listObject.name</td>
<td>listObject.rowStyle</td>
</tr>
</ng-template>
</p-table>
现在,如何将rowStyle属性中指定的样式应用于表的行?
试试这个
<tr style="{{listObject.rowStyle}}">