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

相关内容

热门资讯

透视能赢"poker... 透视能赢"pokerworld辅助器"详细辅助黑科技教程(从前真的有挂);人气非常高,ai更新快且高...
透视工具"wepok... 透视工具"wepoker永久免费脚本"详细辅助详细教程(一向有挂);建议优先通过wepoker永久免...
透视科技"菠萝辅助器... 透视科技"菠萝辅助器免费版的功能介绍"详细辅助微扑克教程(竟然是真的有挂);菠萝辅助器免费版的功能介...
透视美元局"wepo... 透视美元局"wepoker辅助器有哪些功能"详细辅助德州论坛(一向存在有挂);人气非常高,ai更新快...
透视私人局"aapo... 1、透视私人局"aapoker脚本怎么用"详细辅助必赢教程(固有真的有挂);详细教程。2、aapok...
透视玄学"wepok... 透视玄学"wepoker辅助器官方"详细辅助2025新版教程(一直真的有挂)是一款可以让一直输的玩家...
透视辅助"wepok... 透视辅助"wepoker怎么发冤家牌"详细辅助AI教程(一向有挂);《WPK辅助透视》‌:支持手机实...
透视安卓版"impo... 透视安卓版"impoker辅助"详细辅助黑科技教程(真是是有挂)关于impoker辅助机制的,其中提...
透视透视"aapok... 透视透视"aapoker怎么控制牌"详细辅助力荐教程(都是是真的有挂);1分钟了解详细教程(微信 1...
辅助透视"sohoo... 1、辅助透视"sohoo poker辅助"详细辅助揭秘教程(最初是有挂)。2、sohoo poker...