Raymond the Developer
Raymond the Developer

Reputation: 1676

Manually add ng animate to element

Is it possible to manually add NG animate to an element?

For example I want to add ng-enter and ng-leave when a ng-class is added or removed. But I also need ng-enter-active and ng-leave-active classes that gives me more control over the animation process.

Upvotes: 7

Views: 270

Answers (2)

user4226210
user4226210

Reputation:

Yes, you can. But you've to do some trick here like following.

Use https://daneden.github.io/animate.css/ for your application. It has nice animations by default. If you add this to your element, whenever the element inserted to the dom, there will be an animation.

But here in your scenario, add animate class whenever you add or remove class from your elements based on your condition. The sample code is below.

   <div ng-class="AddClass?'yourClass animated fadeIn':'animated fadeOut removedClass'"> 
</div>

Upvotes: 3

Shamal Perera
Shamal Perera

Reputation: 1671

It is not possible to remove a directive based on a class change in ng-class. However since you are applying a class in ng-class based on a condition, you could use that same expression in ng-if to include ng-enter or ng-leave.

Upvotes: 0

Related Questions