I want to add a class using $animate in my directive:
app.directive( 'animTest', [ '$animate', function( $animate ) {
return function( scope, element, attrs ) {
element.on( 'click', function() {
if( element.hasClass( 'clicked' ) ) {
console.log( '[remove]' );
$animate.removeClass( element, 'clicked' );
} else {
console.log( '[add]' );
$animate.addClass( element, 'clicked' );
}
});
};
}]);
CSS:
.clicked {
background: red;
}
.clicked-add, .clicked-remove, .clicked-add-active, .clicked-remove-active {
-webkit-transition: all linear 0.5s;
transition: all linear 0.5s;
}
But the class is never added.
Any idea?
UPDATE - added plnkr: https://plnkr.co/edit/zczgsnLuXONfU8U5mIuv - logs only '[add]' to each click