Search code examples
angularjsng-class

ng-class removes a class but does not put it back


In angular.js, I'm trying to apply a set of classes based on the value of a variable on $scope. But when I set a pair of space-delimited classes, ng-class seems to be removing any that are already present (and it doesn't put them back).

See the Fiddle here: http://jsfiddle.net/fLf0fenj/

Try clicking any of the gray buttons. An icon will appear. It's one from Font Awesome, and the class is fa fa-whatever. Now click another of the gray buttons. The icon should turn into another Font Awesome icon, but instead of that element having two classes (fa fa-something-else), it just has the fa-something-else, so it looks like a square.

If you instead click a gray button, and then the green button, it's all fine. Because that green button uses a glyphicons icon, and so the class names are all being switched out each time.

How do I get around this behavior?


Solution

  • Try

    ng-class="statusIcon()"
    

    And here's a working fiddle