我正在尝试实现角度路线动画。我已经阅读了该文档,并参考了该视频:https://www.youtube.com/watch?v=7JA90VI9fAI。但是我无法使动画正常工作。这是到目前为止的代码:https://stackblitz.com/edit/angular-animations-not-working
import { trigger, transition, animate, style, query } from '@angular/animations';
export const fader =
trigger('routeAnimations', [
transition('* <=> *', [
query(':enter, :leave', [
style({
position: 'absolute',
left: 0,
width: '100%',
opacity: 0,
transform: 'scale(0) translateY(100%)'
})
], { optional: true }),
query(':enter', [
animate('600ms ease', style({
opacity: 1, transform: 'scale(1) translateY(0)'
})),
], { optional: true })
])
]);
<a [routerLink]="['home']">Home</a> <a [routerLink]="['hello']">Hello</a>
<div class="route-content" [@routeAnimations]="prepareRoute(outlet)">
<router-outlet #outlet="outlet"></router-outlet>
</div>
import { Component } from '@angular/core';
import { fader } from './animations';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
fader
]
})
export class AppComponent {
name = 'Angular';
prepareRoute(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
}
}
.route-content {
position: relative;
}
有人可以帮忙吗?
谢谢。
答案 0 :(得分:1)
您需要在路线中添加数据:{animation:'HomePage'}
{ path: 'home', component: HomeComponent, data: {animation: 'HomePage'} },