This is mentioned briefly (too briefly, in my opinion) in the ngClass
documentation. If you pass an object to ngClass
, then it will apply each key of the object as a class to the element if that key’s value is true. For example:
$scope.first = true
$scope.second = false
$scope.third = true
with
<div ng-class="{a: first, b: second, c: third}"></div>
would result in
<div class="a c"></div>