The following is an example of a fading animation for elements generated in a *ngFor .
my.component.ts
@Component({ selector: ..., templateUrl: 'my-component.html', styleUrls: ..., animations: [ trigger('fadeIn', [ transition(':enter', [ style({ opacity: '0' }), animate('.5s ease-out', style({ opacity: '1' })), ]), ]), ], })
my-component.html
<div [@fadeIn]="''" *ngFor="let item of myArray">I'm an Item</div>
NB: we do not use states for our animation, therefore an empty line for state is not needed. (it works just with: [@fadeIn] )
NB: even if the application has βno componentsβ, it still has app.component.ts in which you can do this.
source share