Using AngularJS and ng-class, I'm trying to animate when classes change between three possible states. I have a div that can be in three states, represented by classes on the div. The states are defined as follows:
<div class='myDiv'></div><div class='myDiv foo'></div><div class='myDiv bar'></div>
Note that the classes foo and bar are exclusive meaning <div class="myDiv foo bar"></div> is not possible. I'm using the ng-class directive as follows:
<div class="myDiv" ng-class="{foo: first, bar: second}"></div>
The controller ensures that the boolean values first and second can both be simultaneously false but not true.
I'm finding that ngAnimate correctly detects css transitions between states 1<-->2 and 1<-->3 but does not from 2<-->3. I've tried adding css transition code for class selectors such as .myDiv.foo, .myDiv.bar, .myDiv.foo-add-active, etc. but either ngAnimate doesn't detect them (meaning it doesn't add the -add and -add-active classes) or the animation classes are added but no transition occurs.
Here is a link to a jsFiddle demonstrating the problem. Clicking either button and then re-clicking it shows the working transitions. Clicking either button and then clicking the other button shows the lack of transitions.
Is there a magic set of transitions that ngAnimate will pick up properly? Or is this a case where I need to not use ng-class and write my own custom directive?