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

相关内容

热门资讯

2027版辅助!麻将胡了辅助多... 2027版辅助!麻将胡了辅助多功能AI方法,麻将胡了果然有辅助方法麻将胡了透视方法中分为三种模型:麻...
2027版透视挂!雀友会广东麻... 2027版透视挂!雀友会广东麻将透视挂多功能AI软件,雀友会广东麻将总是是有透视挂软件1、全新机制【...
2027版开挂!乐暴延边麻将开... 2027版开挂!乐暴延边麻将开挂多功能AI攻略,乐暴延边麻将真是是真的有开挂攻略1、金币登录送、破产...
2027版开挂!麻友圈2开挂多... 2027版开挂!麻友圈2开挂多功能AI软件,麻友圈2果然真的有开挂软件1、该软件可以轻松地帮助玩家将...
2027版透视器!闲乐棋牌透视... 2027版透视器!闲乐棋牌透视器多功能AI方法,闲乐棋牌确实真的有透视器方法1、下载好闲乐棋牌脚本下...
2027版辅助!乐易四川麻将辅... 2027版辅助!乐易四川麻将辅助多功能AIapp,乐易四川麻将一贯真的有辅助app1、乐易四川麻将免...
2027版透视挂!哈狗透视挂多... 您好,哈狗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏...
2027版作弊器!桃乐甘肃麻将... 2027版作弊器!桃乐甘肃麻将作弊器多功能AI脚本,桃乐甘肃麻将一贯存在有作弊器脚本2027版作弊器...
2027版外挂!皮皮云南麻将外... 2027版外挂!皮皮云南麻将外挂多功能AI教程,皮皮云南麻将都是存在有外挂教程1、金币登录送、破产送...
2027版外挂!嵊州越乡游麻将... 2027版外挂!嵊州越乡游麻将外挂多功能AI脚本,嵊州越乡游麻将一直有外挂脚本1、嵊州越乡游麻将有没...