1

I have a pretty complex ng-repeat. The number of displayed items can be controlled by two buttons. The first button removes a single element from the ng-repeat by using a filter. The second button removes a bunch of elements and displays a bunch of other elements (also by using a filter).

I currently have an animation on the ng-repeat like this:

<style>
   .animation {
    -webkit-transition: 1s;
  }
  .animation.ng-enter {
    opacity: 0;
  }
  .animation.ng-enter.ng-enter-active {
     opacity: 1;
   }
   /* Similar for ng-leave */
</style>

<div class="animation" data-ng-repeat="item in items"> ... </div>

When the user clicks the first button I want the elements to use the animation. When the user clicks the second button I want to disable any animations.

I'm using AngularJS 1.2.16.

1 Answer 1

2

You could use ng-class directive to have animation class conditionally. Remove animation class when you don't want it, specifically saying on click of second button.

<div ng-class="{animation: expression }" data-ng-repeat="item in items"> ... </div>

In above snippet expression will be condition/scope variable which will set to false so that animation will get removed and animation will get disabled.

Sign up to request clarification or add additional context in comments.

2 Comments

I think that if the function is doing more stuff in the controller, it should first set the expression to false, and then put the rest of the code inside a $timeout (or something like that) to allow the view to render and remove the animation class
@AlonEitan Thank you, the timeout was necessary indeed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.