title: AngularJS $animate addClass not working when started from $swipe action
body: <p>I created an animated slider with AngularJS and jQuery. The sliding animation works when run by clicking one of two buttons I included (Left and Right). The animation doesn't work when I try to fire it from a $swipe action.</p>
  
  <p>In the swipe scenario $animate.addClass() doesn't add the class that should set off the animation.</p>
  
  <p>You can try it here: <a href="http://plnkr.co/edit/oUVzHoR8kFHB3ZZAzPpQ?p=preview" rel="nofollow">http://plnkr.co/edit/oUVzHoR8kFHB3ZZAzPpQ?p=preview</a></p>
  
  <p>First click on of the buttons and you will see the slides animating. Then drag over the slides with your mouse. In the browser console you will see 'move it!' which is printed right before the animation should start, but then... nothing happens. Do you know why?</p>
  
  <p>Adding ng-swipe-left / -right attributes works by the way. But I want custom sliding behavior.</p>
  
  <p>Here is the code for reference:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" ng-app="myApp"&gt;
  &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
  
      &lt;script src="//code.jquery.com/jquery-2.1.1.min.js"&gt;&lt;/script&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular.min.js"&gt;&lt;/script&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular-animate.js"&gt;&lt;/script&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular-touch.js"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
  
          var app = angular.module('myApp', ['ngAnimate', 'ngTouch']);
  
          app.directive('sliderbox', ['$animate', '$swipe', '$log', function ($animate, $swipe, $log) {
              return {
                  restrict: 'E',
                  replace: false,
                  link: function (scope, element, attrs) {
  
                      scope.moveLeft = function () {
                          move('move-left')
                      };
  
                      scope.moveRight = function () {
                          move('move-right')
                      };
  
                      function move(directionClass) {
  
                          $log.info("Starting moving " + directionClass);
  
                          if (directionClass != null) {
                              // Find child elements with the boxslide class
                              var slides = element.find('.boxslide');
                              // Get the left-most slide
                              var leftMostSlide = slides[0];
  
                              if ((!$(leftMostSlide).is(':animated'))) {
                                  $log.info("Move it!");
                                  $animate.addClass(leftMostSlide, directionClass).then(function () {
                                      $(leftMostSlide).removeClass(directionClass);
                                  });
                              }
                          }
                      }
  
                      var posX;
                      var posY;
  
                      $swipe.bind(element, {
  
                          'start': function (coords) {
                              posX = coords.x;
                              posY = coords.y;
                          },
                          'move': function (coords) {
  
                          },
                          'end': function (coords) {
                              var delta = coords.x - posX;
                              if (delta &gt; 50) {
                                  $log.info("Hit move right threshold");
                                  scope.moveRight();
                              } else if (delta &lt; -50) {
                                  $log.info("Hit move left threshold");
                                  scope.moveLeft();
  
                              }
                          },
                          'cancel': function (coords) {
                              // ..
                          }
                      });
                  }
              };
  
  
          }]);
  
          app.animation('.boxslide', ['$log', function ($log) {
              return {
                  addClass: function (element, className, done) {
  
                      var movePixels = 130; // (78px + 2 * 25px padding + 2 * 1px border)
                      var direction = '';
  
                      if (className === 'move-left') {
                          direction = '-=';
                      } else if (className == 'move-right') {
                          direction = '+=';
                      }
  
                      $log.info("MOVING: " + className);
  
                      element.animate({marginLeft: direction + movePixels}, 500, done);
  
                  }
              }
          }]);
  
      &lt;/script&gt;
  
      &lt;style&gt;
          sliderbox {
              display: block;
              border: 1px solid blue;
              overflow: hidden;
              white-space: nowrap;
          }
  
          .boxslide {
              border: 1px solid gray;
              background-color: #ececec;
              padding: 25px;
              width: 78px;
              display: inline-block;
              float: none;
              vertical-align: top;
              margin: 0;
          }
      &lt;/style&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;sliderbox&gt;
      &lt;div class="boxslide"&gt;
          &lt;div&gt;
              Slide 1
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!--
                  This comment prevents white space between box slides
                  --&gt;
      &lt;div class="boxslide"&gt;
          Slide 2
      &lt;/div&gt;
      &lt;!--
                  This comment prevents white space between box slides
                  --&gt;
      &lt;div class="boxslide"&gt;
          Slide 3
      &lt;/div&gt;
  &lt;/sliderbox&gt;
  
  &lt;button ng-click="moveLeft()"&gt;Left&lt;/button&gt;
  &lt;button ng-click="moveRight()"&gt;Right&lt;/button&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>