I'm triggering an animation when I update the collection I pass into *ngFor
:
//JS
state : string = 'a';
colors = {
a: ['red','blue','green','yellow'],
b: ['orange']
}
public onClick (){
this.state = this.state === 'a' ? 'b' : 'a';
}
//HTML
<div *ngFor="let color of colors[state]"
[@animationState]="state"
(click)="onClick()">
{{color}}
</div>
The problem: While the animation is happening, colors from both a
and b
display, which makes the animation jerky.
I've tried:
- setting
transform: scale(0)
ordisplay:none
before thevoid => *
animation begins - delaying the
void => *
animation by the duration of the* => void
animation
I want: to smoothly fade and/or slide out my existing content before (or while) the new content fades/slides in.
Here's a plunkr that demonstrates the problem: https://plnkr.co/edit/IDE6q6lJ84QI2Zirvn4P?p=preview
I managed to make it work, but it feels like a hack. Instead of setting the
ngFor
collection to the new value immediately, IngFor
collection to an empty collectionThis triggers two animations instead of one, but seems to work well.