Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - How to define animation parameters default values?

I am working with Angular animations, and to improve my animation, I need to use parameters. To do so, I did as this answer suggested, with interpolation.

Here is what I have for the state :

state('position', style({ transform: 'translateX({{translate_X}}) translateY({{translate_Y}}) skewX({{skew_X}}) skewY({{skew_Y}})' }))

component.html

<div class="iris" [@move]="{value: triggerValue, params: {translate_X: translate_X, translate_Y: translate_Y, skew_X: skew_X, skew_Y: skew_Y}}"></div>

And here is the error I didn't manage to solve :

ERROR Error: The animation trigger "move" has failed to build due to the following errors: - state("position", ...) must define default values for all the following style substitutions: translate_X, translate_Y, skew_X, skew_Y at InjectableAnimationEngine.AnimationEngine.registerTrigger (...)

So where and how should we define Angular animation parameters default values ?

like image 742
br.julien Avatar asked Dec 22 '17 18:12

br.julien


People also ask

What is @keyframes in angular?

keyframeslinkDefines a set of animation styles, associating each style with an optional offset value.

How do I use BrowserAnimationsModule?

The BrowserAnimationsModule must be imported in the main module of the application app. module. ts and after importing, it is necessary to restart the application so that the imported module is recognized.

Which statements are applicable for animation in angular?

Animation state and styleslinkUse Angular's state() function to define different states to call at the end of each transition. This function takes two arguments: A unique name like open or closed and a style() function. Use the style() function to define a set of styles to associate with a given state name.


1 Answers

I'm not sure if it's too late, but the as the console says, you must add a default value for the animation and you can do it by adding

{params: {your_variable_name: 'default_value'}}

in you animation state, like this:

state('in', style({height: '{{maxHeight}}px',}), {params: {maxHeight: '0'}})

Hope it helps!

like image 117
soni Avatar answered Sep 25 '22 22:09

soni