javascript - 为什么我的 :leave-Animation 不起作用,尽管 :enter-animation 有效?
问题描述
在我的 home.component.html 中:如果我单击图标,该函数会将activateProfileSidebar
布尔值设置showProfileSidebar
为 true。
<i class="fas fa-user-circle user-icon" *ngIf="user" (click)="activateProfileSidebar()"> {{user.username}} </i>
<app-profile-navbar *ngIf="showProfileSidebar"></app-profile-navbar>
和 home.component.ts
ngOnInit(): void {
this.sharedSrv.getShowProfileSidebar().subscribe(value => this.showProfileSidebar = value);
}
activateProfileSidebar(){
this.sharedSrv.setShowProfileSidebar(true);
}
:enter-Animation 工作正常,在我的 profile-navbar.component.html 中,您可以关闭 profile-sidebar。
<nav id="sidebar" class="sidebar-wrapper" [@fade]>
<i class="fas fa-times" (click)="closeProfileSidebar()"></i>
</nav>
profile-navbar.ts 文件
@Component({
...
animations: [
trigger('fade', [
transition(':enter', [
style({'width': '0' }),
animate(200, style({'width': '260px'}))
]),
transition(':leave', [
animate(200, style({'width': '0px'}))
])
])
]
})
...
closeProfileSidebar(){
this.sharedSrv.setShowProfileSidebar(false);
}
奇怪的是,只有 :enter-Animation 有效,但如果我再次关闭配置文件侧边栏,则 :leave-Animation 不起作用。
解决方案
推荐阅读
- assembly - 如何在裸机上获取平面二进制代码地址?
- scala - 演员上的scala.MatchError
- c# - 客户详细信息页面未正确重定向。它没有在 ActionName 之后附加“Id”输入参数
- java - 异步任务减慢问题
- css - 相对于不是其直接父元素的元素,如何以 % 为单位定义容器的宽度?
- c# - 为什么有时在运行游戏时,游戏中的文字字幕是黑色的?
- android - 如何通过 android 下拉菜单/布局上的手势实现展开/折叠?
- c# - 使用 pax 设备在 c# 或 Vb.net 中集成 POS 链接支付
- r - 我想在我的代码中使用热图,但出现错误
- java - 使用黄瓜 v1.2.4 时运行黄瓜测试的方法没有签名