Angular路由转换动画报错(缺少模块)
创始人
2024-10-28 06:00:48
0
  1. 确认是否安装了 @angular/animations 模块,如果没有安装则需要安装它。

  2. 在 app.module.ts 文件中导入 BrowserAnimationsModule 并将其添加到 imports 数组中:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// ...
@NgModule({
  imports: [
    // ...
    BrowserAnimationsModule
  ],
  // ...
})
export class AppModule { }
  1. 在路由组件中添加动画代码,例如:
import { Component } from '@angular/core';
import {
  trigger,
  transition,
  style,
  animate,
  query,
  stagger
} from '@angular/animations';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  animations: [
    trigger('routeAnimations', [
      transition('* <=> *', [
        query(':enter, :leave', [
          style({
            position: 'absoulte',
            left: 0,
            width: '100%'
          })
        ]),
        query(':enter', [
          style({left: '-100%'})
        ]),
        query(':leave', animate('300ms ease-out', style({left: '100%'}))),
        query(':enter', animate('300ms ease-out', style({left: '0%'})))
      ])
    ])
  ]
})
export class AppComponent {
}
  1. 确认路由组件中使用了以下属性:

  1. 通过在路由定义中添加 data 属性来指定动画名称,例如:
const routes: Routes = [
  { path: '', component: HomeComponent, data: {animation: 'home'} },
  { path: 'about', component: AboutComponent, data: {animation: 'about'} },
  { path: 'contact', component: ContactComponent, data: {animation: 'contact'} }
];

相关内容

热门资讯

wepoke辅助德之星(透视)... wepoke辅助德之星(透视)wopoker辅助(详细辅助新2025教程)真是真的有挂(玩家ai机器...
we辅助poker德之星(透视... we辅助poker德之星(透视)wepoke辅助挂在哪开(详细辅助新2025版)确实是真的有挂(大神...
wepoke黑科技(透视)we... wepoke黑科技(透视)wepoke挂真的假的(详细辅助揭秘攻略)竟然存在有挂(攻略计算辅助)1、...
wepoke智能ai(透视)w... wepoke智能ai(透视)wepower让系统发好牌(详细辅助教你攻略)真是真的有挂(详细有挂)1...
wepokeai代打的胜率(透... wepokeai代打的胜率(透视)wepoke ai代打(详细辅助系统教程)真是真的有挂(普及辅助技...
WePoKe透视挂(透视)we... WePoKe透视挂(透视)wepoke是什么软件(详细辅助2025新版教程)竟然存在有挂(普及有辅助...
wepoke黑科技(透视)we... wepoke黑科技(透视)wepoke真的有挂嘛(详细辅助AI教程)其实是真的有挂(普及有挂)1、任...
wepoke有辅助挂(透视)W... wepoke有辅助挂(透视)We辅poker助(详细辅助揭秘教程)原来是真的有挂(专业辅助德之星)1...
wepoke是真的有挂(透视)... wepoke是真的有挂(透视)wepoke支持安卓吗(详细辅助AI教程)其实有挂(攻略ai代打)1、...
wepoke插件(透视)wep... wepoke插件(透视)wepower软件(详细辅助细节揭秘)确实有挂(玩家有辅助挂)小薇(透视辅助...