I am trying to do what looks like a simple process: to display a list of items received from an HTTP request with animation.
First of all, here is my way of doing it ( I am open to any suggestions to do it in a better angular way ):
- I define a scope variable
state
that I initialize toloading
in my controller and that I change toloaded
when I receive data from the HTTP request. - I initialize a scope variable
items
with the received data. - In my view, I use
ng-switch
for the states, andng-repeat
with the items. - I define an animation with css on
ng-repeat
.
Here is a plunkr ( with a $timeout instead of the request ).
I cannot understand why the animation does not work.
Any help will be appreciated. Thanks.
The reason it is happening is because your
ng-when
. The same thing happens withng-if
, but would work fine if you usedng-show
.The problem is that when your
ng-when
condition returns true, theng-when
first renders it's content in a detatched dom (so animations do not happen). This dom is then attached to the dom tree (this step is animated but you would have to put your animation class on the ng-when).When using something like
ng-show
orng-hide
things work as expected because the dom is always attached (it is simply shown/hidden).This might be considered either a bug or a limitation of ng-animate, you might want to post a github issue and see if the angular guys have any thoughts.