angular - ':leave' 转换在 Angular 2+ 应用程序中不会触发
问题描述
我尝试使用@angular/animations 模块制作一个简单的动画,让欢迎文本再次淡入淡出。淡入效果(:enter 过渡)工作得很好,但 :leave 过渡不会触发。我不明白为什么它不起作用。请帮忙 :)
我尝试了两种定义转换的方法(':leave' 或 '* => void'),但没有任何效果。
@Component({
selector: 'app-welcome',
templateUrl: './welcome.component.html',
styleUrls: ['./welcome.component.css'],
animations: [
trigger('fade', [
transition(':enter', [
style({ opacity: 0 }),
animate(4000, style({ opacity: 1 })),
]),
transition(':leave', [
animate(4000, style({ opacity: 0 }))
])
]),
]
})
export class WelcomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
欢迎文本应该在几秒钟后淡入并在几秒钟后再次淡出。淡入作品,不淡出。
模板:
<div class="container-fluid">
<div class="row justify-content-center">
<span class="font-weight-bold" @fade style="font-size:6vw;"> W E L C O M E !</span>
</div>
解决方案
隐藏元素时将:leave
触发。示例堆栈闪电战: https ://stackblitz.com/edit/angular-bxt5w9
推荐阅读
- javascript - Javascript递归:删除只有一个孩子的级别
- javascript - componentWillUnmount 与 React useEffect 挂钩
- php - PHP Soap 方法调用不会返回所有数据,但 __getLastResponse 会
- angular - 获取错误对象(...)的 Ionic App Availability 插件不是函数
- maven - 如何在 jenkins 中安装这些项目,以便只能在一个项目中提供该选项
- c++ - 致命错误:hdf5.h:没有这样的文件或目录
- javascript - Javascript Delete 运算符正在删除两个属性
- machine-learning - 找到信号的基频
- java - Docker – 在 docker 容器中编译 maven 项目并从那里运行它
- android - 如何在odoo mobile中使用多对多关系