Вот демоверсия Stackblitz с угловой анимацией:
Вот некоторые документы об анимации (на которую указывает @ markblue777).
Элемент контейнера оборачивает список элементов, выбитых ngFor. Элемент контейнера содержит анимационный триггер [@listAnimation]
, который должен быть настроен на запрос для каждого из внутренних элементов.
Элементы добавляются последовательно с задержкой, и запускается анимация постепенного увеличения прозрачности.
<div *ngIf="products" class="col-lg-12" [@listAnimation]="items.length">
<div *ngFor="let prod of items" class="col-lg-3 cont" cdkDrag>
<div class="col-sm-offset-2 col-sm-8 productItem">
<p class="text-center">
<img src="https://www.classicposters.com/images/nopicture.gif" width="125" height="160" />
</p>
<p>
<i>{{prod.title}}</i>
<br />
<i >{{prod.price | currency:"£"}}</i>
</p>
</div>
</div>
</div>
<div *ngIf="products" class="row">
<div class="col-lg-12 text-center">
Page {{products.pageOn}} of {{products.totalPages}}
</div>
</div>
import { Component, OnInit } from '@angular/core';
import {
trigger,
style,
query,
stagger,
animate,
transition,
} from '@angular/animations';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('listAnimation', [
transition('* => *', [
query(':enter', [
style({ opacity: 0 }),
stagger(100, [
animate('0.5s', style({ opacity: 1 }))
])
], { optional: true })
])
])
],
})
export class AppComponent implements OnInit {
products = { pageOn: 0, totalPages: 5, data: null };
items = [];
ngOnInit(): void {
this.apiCall().then(products => {
this.products = products;
// We then animate the entry of each item separately
products.data.forEach((product, idx) => {
setTimeout(() => {
this.items.push(product);
}, 500 * (idx + 1)); // Each item is inserted 500ms after the last one.
});
});
}
// Simulate the API call
apiCall(): Promise<any> {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ pageOn: 0, totalPages: 10, data: [
{ title: 'cheese', price: 1 },
{ title: 'chothes', price: 2 },
{ title: 'Food', price: 3 },
]});
}, 2000); // with a delay of 2000ms
})
}
}
Вам нужно будет добавить BrowserAnimationsModule
, чтобы это работало:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';