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

相关内容

热门资讯

详情透视!pokemmo辅助脚... 详情透视!pokemmo辅助脚本!真是存在有辅助教程(有挂秘籍)-哔哩哔哩1、不需要AI权限,帮助你...
总结透视!aapoker发牌逻... 总结透视!aapoker发牌逻辑,hhpoker透视脚本下载,窍门教程(真实有挂)-哔哩哔哩1)hh...
了解透视!xpoker辅助助手... 了解透视!xpoker辅助助手!都是真的有辅助攻略(有挂总结)-哔哩哔哩1、完成xpoker辅助助手...
曝光透视!黑侠破解wepoke... 曝光透视!黑侠破解wepoker,xpoker辅助怎么用,项目教程(有挂方略)-哔哩哔哩1、xpok...
专业透视!wepoker轻量版... 专业透视!wepoker轻量版透视方法,wepoker透视脚本免费下载,绝活儿教程(有挂教学)-哔哩...
总结透视!约局吧开挂神器是真的... 总结透视!约局吧开挂神器是真的吗!一直是有辅助软件(确实有挂)-哔哩哔哩;1、约局吧开挂神器是真的吗...
有挂透视!hhpoker到底可... 有挂透视!hhpoker到底可以作必弊吗,aa poker辅助包,项目教程(真的有挂)-哔哩哔哩1、...
普及透视!pokemmo免费脚... 普及透视!pokemmo免费脚本!总是一直总是有辅助教程(有挂秘笈)-哔哩哔哩所有人都在同一条线上,...
有挂透视!wepoker辅助透... 有挂透视!wepoker辅助透视,aapoker辅助怎么用,诀窍教程(有挂规律)-哔哩哔哩1)aap...
关于透视!哈糖大菠萝有没有挂!... 关于透视!哈糖大菠萝有没有挂!原来是有辅助工具(真的有挂)-哔哩哔哩1、不需要AI权限,帮助你快速的...