【发布时间】:2017-11-01 17:34:46
【问题描述】:
我在我的应用程序中使用选项卡,其内容使用 *ngIf 显示。
我想为这些内容的进入和退出设置动画。示例:plunker
似乎动画 :enter 和 :leave 在组件选择器上不起作用 示例:plunker
template: `
<div>
<h2>Hello {{name}}</h2>
<button (click)="show = !show">togle show ({{show}})</button>
<my-child *ngIf="show" [@myAnimation]></my-child>
</div>
`,
trigger(
'myAnimation',
[
transition(
':enter', [
style({transform: 'translateX(100%)', opacity: 0}),
animate('500ms', style({transform: 'translateX(0)', 'opacity': 1}))
]
),
transition(
':leave', [
style({transform: 'translateX(0)', 'opacity': 1}),
animate('500ms', style({transform: 'translateX(100%)', 'opacity': 0}),
]
)]
)
我尝试将动画移动到子组件,但在那里,ngIF 在动画发生之前删除了元素。
【问题讨论】: