Add animation when expression value changes - Angular 5 Add animation when expression value changes - Angular 5 angular angular

Add animation when expression value changes - Angular 5


the :enter animation will only animate elements that are newly created. Your "hacky" workaround works because it forces the inner span to get recreated whenever the value changes. I think what you want is to remove the :enter query. You want to animate when the number is in/decremented, and your animation has nothing to do with elements being added.


I found a fix from here and here.

<div [@valueAnimation]="pointsBalance"><span *ngFor="let pointsBalance of [ pointsBalance ]">{{ pointsBalance }}</span></div>

Feels a bit hacky though.


I'm just going to paste the code as it would look, as Benjamin Kindle said, I tried it and it worked:

animations: [    trigger('valueAnimation', [      transition(':increment', [          style({ color: 'green', fontSize: '50px' }),          animate('0.8s ease-out', style('*'))        ]      ),      transition(':decrement', [          style({ color: 'red', fontSize: '50px' }),          animate('0.8s ease-out', style('*'))        ]      )    ])  ]