【发布时间】:2021-10-14 17:43:45
【问题描述】:
我正在尝试从管理视图的 popin.component.ts 触发动画。
import { Component, EventEmitter, Input, Output } from "@angular/core";
import {
trigger,
state,
style,
animate,
transition
} from "@angular/animations";
@Component({
selector: "app-popin",
templateUrl: "./popin.component.html",
styleUrls: ["./popin.component.css"],
animations: [
trigger("openClose", [
state(
"open",
style({
transform: "translateY(0%)"
})
),
state(
"closed",
style({
transform: "translateY(100%)"
})
),
transition("* => *", animate(500))
])
]
})
export class PopinComponent {
@Input() isPopinOpen = false;
@Input() isPopinAnimationActive = false;
@Output() isPopinClosed = new EventEmitter<boolean>();
closePopin() {
this.isPopinClosed.emit(this.isPopinAnimationActive);
}
}
父组件管理布尔值以改变状态。
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
isPopinAnimationActive: boolean;
isPopinOpen: boolean;
animate() {
this.isPopinOpen = true;
this.isPopinAnimationActive = true;
}
closeThePopin() {
this.isPopinOpen = false;
this.isPopinAnimationActive = false;
}
}
我有 2 个问题。
1 - 当我关闭 popin 时,向下滑动的动画不起作用。仅当我删除评论中的行时才有效。
closeThePopin() {
// this.isPopinOpen = false;
this.isPopinAnimationActive = false;
}
2 - 似乎角度不读取过渡“打开”和“关闭”的状态
transition("open => closed", animate(500))
只有当我像这样使用 * 时它才有效:
transition("* => *", animate(500))
这里是codesandbox代码:
https://codesandbox.io/s/lucid-wilson-lqzw2?file=/src/app/app.component.ts
【问题讨论】: