【发布时间】:2023-04-06 22:37:02
【问题描述】:
我正在尝试创建一个将在 Angular 2 中的动画结束时触发的函数(我使用的是最新的 Angular cli)。
我一直在 Angular Animations 上了解如何通过为触发器分配回调来实现这一点 在我的代码示例中,我有一个在页面上动画的组件。代码如下:
//first.component.ts
import { Component, OnInit } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/core';
@Component({
selector: 'app-first',
templateUrl: './first.component.html',
styleUrls: ['./first.component.css'],
host: {
'[@routeAnimation]': 'true',
'[style.display]': "'block'",
'[style.position]': "'absolute'"
},
animations: [
trigger('routeAnimation', [
state('*', style({transform: 'translateX(0)', opacity: 1})),
transition('void => *', [style({transform: 'translateX(-100%)', opacity: 0}),animate(500)]),
transition('* => void', animate(500, style({transform: 'translateX(100%)', opacity: 0})))
])
]
})
export class FirstComponent implements OnInit {
constructor() { }
ngOnInit() {
}
myFunc() {
// call this function at the end of the animation.
}
}
html 只是一个 div
<div class="w9914420">
<h2>
first-component Works!
</h2>
</div>
说实话,我对 JavaScript 不太熟悉,所以任何帮助或快速示例都可以帮助我更好地了解 Angular 2。
【问题讨论】: