While trying to build an animation based on velocity.js with AngularJS $animate, I encountered a small problem I couldn't figure for hours, although the solution was very simple. To avoid you the same difficulty, I present to you my solution:
Considering the following code:
app.directive("animate", function ($animate, $timeout) {
return function (scope, element, attrs) {
element.on('click', function () {
// to fire $animate, need to wrap it into a $timeout wrapper.
$timeout(function () {
$animate.addClass(element, 'test').then(function () {
$timeout(function () {
$animate.removeClass(element, 'test');
}, 0);
});
}, attrs.delay || 0);
});
};
});