Need to trigger animation every time the array changes
I am currently iterating over an array of products using *ngfor and everytime the length changes the animation will trigger. I am using Angular 4.
<ul class="items col col-md-12" *ngIf="hasProducts()" [@productsIntro]="products.length">
The issue is that I need the animation to trigger everytime the array changes at all and not just the length of the array. Sometimes the array length will be the same but the items in the array are different so the animation will not trigger.
I am not sure on how to pull this off and was hoping someone could help me out with a solution.
<ul class="items col col-md-12" *ngIf="hasProducts()" [@productsIntro]="products.length">
<li class="col col-xs-12 col-sm-12 col-md-4" *ngFor="let product of products">
<div class="item">
<a href="" class="product-name">{{product.product_name}}</a>
<div class="image-and-info col col-xs-8 col-sm-8 col-md-12">
<div class="product-thumb">
<img src="../../assets/img-filler.png" alt="{{product.product_name}}">
</div>
<div class="info">
<div class="sku">SKU: {{product.sku}}</div>
<div class="price">Price: {{product.price | currency:'USD':true:'1.2-2'}}</div>
</div>
</div>
<div class="product-col col col-xs-4 col-sm-4 col-md-12">
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-solid" (click)="viewProduct(product)">View Product</button>
<button type="button" class="btn btn-solid add-to-cart" (click)="addToCart($event)">Add to Cart</button>
</div>
</div>
</div>
</li>
</ul>
trigger form component:
trigger('productsIntro', [
transition('* => *', [
query(':enter', style({ opacity: 0 }), {optional: true}),
query(':enter', stagger('100ms', [
animate('1s ease-in', keyframes([
style({opacity: 0, transform: 'translateY(-10%)', offset: 0}),
style({opacity: .5, transform: 'translateY(10px)', offset: 0.3}),
style({opacity: 1, transform: 'translateY(0)', offset: 1.0}),
]))]), {optional: true})
])
])