How can i flash cell in table that changed its value?
<tr *ngFor="#product of products" (click)="onSelect(product)">
<td>{{product.productName}}</td>
<td>{{product.price}}</td>
</tr>
in component i have input for products : @Input() products:Array<ProductModel>;
and there is a test timer in parent component that change random product`s price every 3 seconds:
var timer = Observable.timer(2000, 3000);
timer.subscribe(t => this._changeRandomProduct());
private _changeRandomProduct() {
var productCandidate:ProductModel = this.products[randomOf(0, this.products.length)];
productCandidate.price = productCandidate.price + 1;
}
how can i handle value change in price-cell to add css class on it ?
Plunker example
You can just pass the index (or other means to identify the changed item) and add/remove a class used with a CSS animation
@Component({
selector: 'my-products',
styles: [`
.updated {
animation: blinker 1.7s cubic-bezier(.5, 0, 1, 1) infinite alternate;
}
@keyframes blinker {
from { opacity: 1; color: red;}
to { opacity: 0; color: black;}
}`],
template: `
<tr *ngFor="let product of products; let i = index" (click)="onSelect(product)" [ngClass]="{updated: i === updatedIndex}">
<td>{{product.productName}}</td>
<td> - </td>
<td>{{product.price}}</td>
</tr>`,
})
export class MyProducts {
@Input() products:any[];
@Input() updatedIndex:number;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With