I'm trying to make a simple animation like the simple jQuery below
animate({'left' : left_indent})
I'm using the Angular2 Animations but the problem is how do I pass the left_indent parameter outside my Component Class in to the animation trigger?
animations: [
trigger('flyInOut', [
state('for', style({
left: this.left_indent,
})),
transition('* => for', [
animate(2000, keyframes([
style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(-300px)', offset: 0.5 }),
]))
]),
])
]
Now it's possible.
UPDATE (according to SplitterAlex answer):
in template (for Angular < 4.4.6):
for Angular >= 4.4.6 template should be
Currently animations only allow for static definitions of values.
However, according to this git hub feature request raised in June 2016, there is a plan but it appears to still be on the backlog of features to add.
It hasn't been released yet.
The accepted answer doesn't work for me with Angular 4.4.6
You have to wrap the param values in the template in an object
params
Replace:
With:
i have one solution. But it is helpful only if you are trying to use same animation several times with different parameters that you already know.
For example, i have reusable animation for making slideUp-slideDown effect. And in collapsed state container must keep some height (that i already know for these containers).
Animation:
In component's class:
And finaly, in component's html:
Unfortunately it can not be used for dynamic parameters cuz you must define them in decorator & html.