Search code examples
angularjsng-class

Remove a class added conditionally using ng-class


I add a class another-class based on condition as follows using ng-class.Is it possible to remove that another-class using ng-class when the condition is not met? Right now the class another-class just remains in the element even when the condition is not met!

<div ng-hide="ok.isTrue" ng-class = "'{{ok.Id}}' === '{{notok.Id}}' ? 'another-class': '' ;" class="some-class">

Solution

  • You can use different ng-class syntax for this, particularly the map syntax:

    ng-class="{'another-class': ok.Id === notok.Id}"