What is the best way to conditionally apply a class?

后端 未结 22 2734
感动是毒
感动是毒 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:31

    If you are using angular pre v1.1.5 (i.e. no ternary operator) and you still want an equivalent way to set a value in both conditions you can do something like this:

    ng-class="{'class1':item.isReadOnly == false, 'class2':item.isReadOnly == true}"
    

提交回复
热议问题