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
statethat I initialize toloadingin my controller and that I change toloadedwhen I receive data from the HTTP request. - I initialize a scope variable
itemswith the received data. - In my view, I use
ng-switchfor the states, andng-repeatwith 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-whencondition returns true, theng-whenfirst 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-showorng-hidethings 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.