function MyCtrl($scope) {
$scope.active = false;
$scope.toggleActive = function () {
$scope.active = !$scope.active;
};
}
.
<div ng-class="{red: !active, green: active}" ng-click="toggleActive()"></div>
ngClass, when given an object, sets the classes of which property values are truthful.
Note: View's should not contain any business logic as they are hard to test; they only should interact with the controller.
Clarifition on that:
What you shouldn't do is, to change properties in scope directly from your view. Have a function in controller acts as a wrapper which does that for you. View can change how itself is rendered depending on the scope properties and call functions in controller to manipulate data. Also, controllers should not aware of at all how you want to display the data, it should behave like there is no view at all (That in fact, view should be replacable). Which css class you want to apply is not something your controller should know / decide.