I have a list of array items in an ngFor
. I have a simple button the adds an an item to the array. I want to apply an animation to the items when they are added only but although this works, the group of list items already on the page gets the animation on page load. How can I limit the animation only to the newly added item? This is in Angular 10.
I made a stripped-down Stackblitz.
animations: [
trigger("myTrigger", [
state(
"fadeInFlash",
style({
opacity: "1"
})
),
transition("void => *", [
style({ opacity: "0", transform: "translateY(20px)" }),
animate("500ms")
])
])
]
<p>
<button (click)="addItem()">Add Item</button>
</p>
<ul>
<li *ngFor="let item of items" [@myTrigger]='state'>{{item}}</li>
</ul>