2

trying to wrap my head around animating a list of items where users can move items up and down, one at a time, one step at at a time.

I got all excited when the documentation started talking about :increment and :decrement selector values. However, I can't seem to get this to work.

The StackBlitz is up: https://stackblitz.com/edit/angular-j6ejbe

The gist of my code is:

animations: [
  trigger('move', [
    transition(':decrement', [style({ opacity: 0 }), animate('5s ease', style({ opacity: 1 }))]),
    transition(':increment', [style({ transform: 'scale(0.5)' }), animate('5s ease', style({ transform: 'scale(1)' }))]),
  ])
],

my html:

<div [@move]="index" *ngFor="let item of items; let index = index;">
  <span (click)="moveUp(item)">^</span>&nbsp;<span (click)="moveDown(item)">v</span> {{index}} : {{item}} 
</div>

The result is pretty odd:

crazy list

First, it looks like only the :increment transition is kicking in (scale), not the :decrement (opacity). Second, it seems that the transition only fires once per index.

Is this a bug with the transition/animations library?

Or am I just using/understanding it wrong?

Update

Part of the issue seems to be with the *ngFor. If I add a child div element and animate it, things are better, but not 100%.

Two issues still happening:

  1. First, it seems that the :increment is working as expected, but the :decrement takes a couple of rounds to work.
  2. Second, it seems that I have to use an inner div element. I can't seem to put the animation on an ng-container. This is a bit annoying as I don't like adding additional div elements just to hack something.

enter image description here

Eric Liprandi
  • 5,324
  • 2
  • 49
  • 68
  • So, found out something interesting, it seems that the transition trigger on the `*ngFor` element is the culprit. If I simply move everything down one level and apply the transition to a child `div` element, it works... stay tuned! – Eric Liprandi Oct 19 '18 at 14:26
  • Congrats! It seems that you already fixed the issue. Is there any other issues you are facing? – Gerard Sans Oct 22 '18 at 10:34
  • hi @GerardSans thanks for following-up (and thanks for your great article). I am still having the 2 issues I posted in the update where it doesn't seem to work the first couple of times I click on a particular item. This might be a bug and I will get around posted it on angular. The second issue (need to create a child `div` element) might just be a misunderstanding on my part on how to use animations. I kinda had to focus on the actual business logic instead of animations the past couple of days... – Eric Liprandi Oct 22 '18 at 20:28

0 Answers0