本文介绍了动画Angular2中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个简单的动画,例如下面的简单jQuery
I'm trying to make a simple animation like the simple jQuery below
animate({'left' : left_indent})
我正在使用Angular2动画,但问题是如何将Component类外部的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 }),
]))
]),
])
]
推荐答案
现在可以了.
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 }),
]))
]),
])
]
更新(根据SplitterAlex的回答):
在模板中(对于Angular< 4.4.6):
in template (for Angular < 4.4.6):
<div [@flyInOut]="{value: triggerValue, left_indent: left_indent}"></div>
对于Angular> = 4.4.6模板应为
for Angular >= 4.4.6 template should be
<div [@flyInOut]="{value: triggerValue, params: {left_indent: left_indent}}"></div>
这篇关于动画Angular2中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!