Ng-style with condition

后端 未结 7 1565
旧巷少年郎
旧巷少年郎 2021-01-11 09:25

How can I apply style on some item in a list that satisfy listed condition:

        
7条回答
  •  灰色年华
    2021-01-11 10:13

    On Angular >9 the syntax is following:

     [ngStyle]="{'background-color': item.selected ? '#f00' : ''}"
    

    Make sure you do not add a semicolon (;) at the end of the style expression as this breaks the functionality

提交回复
热议问题