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

相关内容

热门资讯

透视能赢!hhpoker德州透... 透视能赢!hhpoker德州透视挂(透视)确实真的是有挂(详细辅助线上教程)1、在ai机器人技巧中,...
透视最新!aapoker怎么设... 透视最新!aapoker怎么设置抽水(透视)总是存在有挂(详细辅助辅助教程)1. ai辅助创建新账号...
透视挂!pokemmo手机辅助... 透视挂!pokemmo手机辅助软件(透视)其实真的有挂(详细辅助玩家教程)1、系统规律教程、辅助透视...
透视辅助!拱趴大菠萝挂哪里(透... 透视辅助!拱趴大菠萝挂哪里(透视)其实存在有挂(详细辅助新版2025教程)1、玩家可以在软件透明挂俱...
玩家必看教程!wepoker怎... 玩家必看教程!wepoker怎么下载游戏,wepoker新号好一点吗,辅助教程(有挂辅助)准备好在w...
透视苹果版!epoker底牌透... 透视苹果版!epoker底牌透视(透视)切实真的有挂(详细辅助wpk教程)1、全新机制【软件透明挂】...
分享一款!wepoker怎么发... 分享一款!wepoker怎么发冤家牌,wepoker模拟器哪个,黑科技教程(有挂透视);实战中需综合...
透视黑科技!we-poker是... 透视黑科技!we-poker是什么软件(透视)果然存在有挂(详细辅助技巧教程)1、系统规律教程、辅助...
总算明白!wepoker脚本,... 总算明白!wepoker脚本,哈糖大菠萝挂,力荐教程(有挂神器);支持多人共享记分板与复盘,通过邀请...
透视好友房!拱趴大菠萝有什么挂... 透视好友房!拱趴大菠萝有什么挂(透视)都是存在有挂(详细辅助技巧教程)1、这是跨平台的黑科技,在线的...