If I have:

ng-class='{in:$first}'

What is the simplest way to make it add the in class when $first is true or if let's say the item.in ($scope.item.in) value is true ?


note: $first is because I have a ng-repeat enclosing this line but it can be any other boolean or 0/1 value if you feel the code is incomplete.

有帮助吗?

解决方案

You can use the || operator like this.

<div ng-class="{ in: $first || item.in }"> Test </div>

Example: http://jsfiddle.net/eLPE8/

其他提示

you can use the or operator in ng-class as such

ng-class="{myclass: condition1 || condition2}"

your element will gain the myclass class if condition1 or condition2 is true.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top