What is the best way to conditionally apply a class?

后端 未结 22 2604
感动是毒
感动是毒 2020-11-22 09:12

Lets say you have an array that is rendered in a ul with an li for each element and a property on the controller called selectedIndex.

22条回答
  •  余生分开走
    2020-11-22 09:20

    Here is another option that works well when ng-class can't be used (for example when styling SVG):

    ng-attr-class="{{someBoolean && 'class-when-true' || 'class-when-false' }}"
    

    (I think you need to be on latest unstable Angular to use ng-attr-, I'm currently on 1.1.4)

提交回复
热议问题