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:nonebefore thevoid => *animation begins - delaying the
void => *animation by the duration of the* => voidanimation
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
ngForcollection to the new value immediately, IngForcollection to an empty collectionThis triggers two animations instead of one, but seems to work well.