diegonetto / stock-dog

Tutorial on building an Angular application.
47 stars 44 forks source link

Animation stops after a few updates on Chapter 1 Step 10 #5

Open jaridmck opened 8 years ago

jaridmck commented 8 years ago

Likely this is because I'm using a newer version of Angular, but I ran into an issue where the animations stopped after each element had been updated once up and once down. Here is the code in the book:

$animate.addClass($element, 'change-' + direction, function() {
  $animate.removeClass($element, 'change-' + direction);
});

I think the code is attempting to remove the class before the animation is complete and causing a problem.To solve this, I modified the above code slightly to make sure that the directive only continues once the animation promise from the addClass function has been returned:

$animate.addClass($element, 'change-' + direction).then( function() {
  $animate.removeClass($element, 'change-' + direction);
});

Reference