The AngularJS Noob Handbook has some code which reduces class manipulation to a simple expression and binding :
...&
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
would result in