Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter in to Animation Angular2

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 }),             ]))         ]),     ]) ] 
like image 879
ahrberg Avatar asked Jan 31 '17 20:01

ahrberg


People also ask

Which animation strategy would you use to apply multiple styles for a transition?

The keyframes() function in Angular allows you to specify multiple interim styles within a single transition, with an optional offset to define the point in the animation where each style change should occur.

How do I disable ng animation?

To disable ng-animate for certain elements, using a CSS class, which follows Angular animate paradigm, you can configure ng-animate to test the class using regex. Simply add the ng-animate-disabled class to any elements you want to be ignored by ng-animate.


1 Answers

Now it's possible.

animations: [     trigger('flyInOut', [          state('for', style({             left: '{{left_indent}}', // use interpolation         }), {params: {left_indent: 0}}), // default parameters values required          transition('* => for', [             animate(2000, keyframes([                 style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),                 style({ opacity: 1, transform: 'translateX(-300px)', offset: 0.5 }),             ]))         ]),     ]) ] 

UPDATE (according to SplitterAlex answer):

in template (for Angular < 4.4.6):

<div [@flyInOut]="{value: triggerValue, left_indent: left_indent}"></div> 

for Angular >= 4.4.6 template should be

<div [@flyInOut]="{value: triggerValue, params: {left_indent: left_indent}}"></div> 
like image 129
EvgenyV Avatar answered Oct 07 '22 03:10

EvgenyV