【发布时间】:2019-11-03 17:23:00
【问题描述】:
我正在尝试用 angular 实现一个简单的动画。单击按钮时,我将showState 的状态从shown 更改。由于我使用 *ngIf 我在动画中使用了 void 关键字,但它不起作用。
CSS
p {
border: 1px solid black;
background-color: lightblue;
padding: 10px;
}
app.component.ts
import { showStateTrigger } from './animations';
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
animations: [
showStateTrigger
]
})
export class AppComponent {
isShown = false;
}
HTML
<button (click)="isShown = !isShown">Toggle Element</button>
<p [@showState]="isShown ? 'shown' : 'notShown'" *ngIf="isShown"> You can see me now!</p>
Animations.ts
从“@angular/animations”导入{状态、样式、过渡、触发器、动画};
export const showStateTrigger = trigger("showState", [
transition('void => shown', [
style({
opacity: 0
}),
animate(2000, style({
opacity: 1
}))
])
]);
【问题讨论】:
标签: javascript css angular animation angular-animations