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

相关内容

热门资讯

透视好友房"wepo... 1、透视好友房"wepoker辅助器"详细辅助介绍教程(透视脚本免费透视)(UU poker、wep...
辅助透视"wepok... 辅助透视"wepoker分析"详细辅助新版2025教程(辅助机器人透明);1分钟了解详细教程(微信 ...
透视app"hhpo... 透视app"hhpoker德州透视挂"详细辅助揭秘教程(透视有教程);hhpoker德州透视挂软件透...
透视讲解"hhpok... 透视讲解"hhpoker作弊码"详细辅助黑科技教程(模拟器哪个好用方法)准备好在hhpoker作弊码...
透视苹果版"拱趴大菠... 1、透视苹果版"拱趴大菠萝十三水作弊"详细辅助德州教程(辅助器方法);详细教程。2、拱趴大菠萝十三水...
辅助透视"德州局透视... 辅助透视"德州局透视脚本"详细辅助普及教程(私局辅助技巧)科技教程也叫必备教程,这是一款功能强大的德...
透视苹果版"wepo... 透视苹果版"wepoker新号好一点吗"详细辅助透视教程(智能辅助插件攻略)准备好在wepoker新...
透视中牌率"德普之星... 透视中牌率"德普之星怎么设置埋牌"详细辅助2025版教程(辅助机器人教程)是一款可以让一直输的玩家,...
透视好牌"拱趴大菠萝... 透视好牌"拱趴大菠萝挂怎么安装"详细辅助必备教程(永久免费脚本神器)是一款可以让一直输的玩家,快速成...
透视挂透视"wepo... 透视挂透视"wepoker代打辅助"详细辅助玩家教程(可以开辅助辅助);人气非常高,ai更新快且高清...