Search code examples
javascriptangularjsng-class

Angular ng-class with class


I've found similar questions here but not this and its a most simple use case: using class and ng-class on the same element.

I have a UL generated with ng-repeat. The LI get styling with an .item class and the selected LI gets an .active class added dynamically with ng-class if it's the currently selected LI (user).

If I only use ng-class, it works. But, when I want to add a standard class, it does not.

Whats up? Much thanks ---

This works and the selected LI gets the .active class.

<li ng-repeat="user in mainList.users" ng-class="{'active':isCurrentUser(user)}">

This doesn't work:

<li ng-repeat="user in mainList.users" class="item" ng-class="{'active':isCurrentUser(user)}">

Solution

  • Well there is always a workaround :D :

    <li  ng-repeat="user in mainList.users" ng-class="{'item' : true, 'active': isCurrentUser(user)}">
       {{user}}
    </li>
    

    Im not sure your suppose to have those quotations when your calling the classes in ng-class but if one dosent work check the other. Hope this helped!