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'} }
];

相关内容

热门资讯

透视总结!wepoker怎么拿... 透视总结!wepoker怎么拿到好牌,we poker辅助器v3.3(透视)介绍教程(有挂插件);w...
辅助透视!wepoker底牌透... 辅助透视!wepoker底牌透视,wepoker透视辅助下载(透视)透明挂教程(有挂辅助)1、wep...
透视黑科技!wepoker插件... 透视黑科技!wepoker插件程序激活码,wepoker作弊辅助(透视)必备教程(有挂技巧)1、构建...
透视了解!we-poker软件... 透视了解!we-poker软件,wepoker透视脚本免费下载pc(透视)普及教程(有挂脚本);所有...
透视有挂!wepoker到底有... 透视有挂!wepoker到底有没有透视,wepoker破解工具(透视)新版2025教程(有挂详情)1...
透视计算!wepoker轻量版... 透视计算!wepoker轻量版有透视吗,wepoker有辅助插件吗(透视)wepoke教程(有挂详情...
透视ai!wepoker辅助器... 透视ai!wepoker辅助器如何使用,wepoker辅助器(透视)必赢方法(有挂规律)1、起透看视...
透视好友!wepoker有插件... 透视好友!wepoker有插件吗,wepoker游戏的安装教程(透视)软件教程(有挂规律);1、操作...
透视游戏!wepoker有辅助... 透视游戏!wepoker有辅助工具吗,wepoker私人局辅助器怎么用(透视)安装教程(有挂细节)1...
透视私人局!wepoker怎么... 透视私人局!wepoker怎么破解游戏,wepoker透视脚本下载(透视)可靠教程(有挂黑科技)1、...