I am trying to animate a value whenever the text changes in my Ionic 2 (Angular 2) project. This is in an Ionic2 project, but should be the same for any Angular2.
I have the following in the markup..
<ion-list no-lines>
<ion-item *ngFor="let item of data>
<ion-card [@flyInOut]='cardState'>
<ion-card-content>
<div ><b>{{item.name.description}}</b></div>
<div [@valueUpdated]='item.lastname.description'>{{item.lastname.description}}</div>
<div>{{item.value}}</div>
</ion-card-content>
</ion-card>
</ion-item>
</ion-list>
and the following trigger in the component..
trigger('valueUpdated',[
state('void => *',style({
backgroundColor:'red'
})),
state('* => void',style({
backgroundColor:'green'
})),
transition('active => inactive', animate('100ms ease-in')),
transition('inactive => active', animate('100ms ease-out'))
])
I am just using colors here to test, eventually I'd want it to change change color (and then change back), or perhaps have the old value "flyout" and the new to "flyin" (similar as the example in the Angular documentation.
However, before that, I just want to see if this is possible. I am new to the playing with the animations, so perhaps I am right off track?
Is it possible to do this, and if so how?
Any help greatly appreciated!
[UPDATE]
I have come close with the following, using translateX fot testing rather than color changes (as it is easier to see) ...
trigger('valueUpdated', [
state('* => *', style({ transform: 'translateX(0)' })),
transition('* => *', [
animate(2000, style({ transform: 'translateX(100%)' }))
])
]),
When the element is first added I see the above animated translateX occurring, however went the state, ie item.name.description
is changed, the div shoots straight to translateX(100%), and then back to translateX(0) with no animation to the translateX(100%), so still not quite right.
[UPDATE2]
I have found something comes closer..
trigger('valueUpdated', [
state('void => *', style({ transform: 'translateX(0)' })),
transition('void => *', []),
transition('* => *', [
animate(2000, style({ transform: 'translateX(100%)' }))
])
]),
Adding the void => *
state and transition stopped the animation occurring when the element is first added. It is now only animates when the text is first changed from it's initial value, but not any subsequent times, so still not right.