【问题标题】:How to apply dynamic style for the PrimeNg table rows?如何为 PrimeNg 表格行应用动态样式?
【发布时间】:2020-12-23 23:30:14
【问题描述】:

我有 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 属性中指定的样式应用于表格的行?

【问题讨论】:

  • 试试这个&lt;tr [style]="listObject.rowStyle"&gt;

标签: angular typescript primeng


【解决方案1】:

试试这个

<tr style="{{listObject.rowStyle}}">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 2018-09-26
    • 2019-08-05
    相关资源
    最近更新 更多