I have a div where I have some values in an array displayed in it and I can add more. The newly added value will be added directly to the div:
list = ['milk', 'sugar', 'flour'];
state = 'normal';
//@ViewChild('f') addForm: NgForm;
onAdd(item)
{
this.list.push(item);
//this.addForm.reset();
}
I have this simple animation:
animations: [
trigger('divState', [
state('normal', style({
backgroundColor: 'red',
transform: 'translateX(0)'
})),
state('highlighted', style({
backgroundColor: 'blue',
transform: 'translateX(100px)'
})),
transition('normal=>highlighted', animate(300)),
transition('highlighted=>normal', animate(800))
])
]
That is applied to a div, where it will be animate it.
What I really need is to apply a flashing red color, to the newly added value of the array for few milliseconds like flash.
So if I have the following:
Milk
Sugar
Flour
And then added Eggs:
Milk
Sugar
Flour
Eggs
And the Eggs div should flash.
I know that I should work on the index, by getting the last added index and apply the animation on it:
<li
class="list-group-item"
*ngFor="let item of list; let i = index" >
{{ item }}
</li>
I tried the following:
<li [@divState]="state"
class="list-group-item"
*ngFor="let item of list; let i = index" >
{{ item }}
</li>
So all the divs are highlighted.
How can apply this animation (basically I am not focusing on the animation as itself so I will apply a simple red color to it) using the index so by that, I can show the newly added element of the array.