Angular toggle html class on click


How to toggle class of some element with Angular

Enter ng-class object. First (highlight) will be the class added to the element:

<div ng-class="{highlight:onOff}"> Highlight this box </div>

When pressed button element will toggle class inside element with ng-class:

<button ng-click="onOff=!onOff">Toggle</button>

Another example:

<p ng-click="onOff=!onOff" ng-class="{highlight:onOff}" ng-repeat="todo in todos | filter:search"> @{{todo.todo}} </p>