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

相关内容

热门资讯

今天下午!微乐小程序黑科技,微... 今天下午!微乐小程序黑科技,微信小程序微乐辅助器贴吧(透视)一贯是有辅助技巧(哔哩哔哩)该软件可以轻...
透视指引!wepoker好友局... 透视指引!wepoker好友局透视(WePoKer分析器)真是真的是有辅助app(哔哩哔哩)1、we...
经调查!微乐小程序黑科技,微乐... 经调查!微乐小程序黑科技,微乐小程序辅助器脚本(透视)一直真的有辅助脚本(哔哩哔哩)1、下载好正确养...
透视方针!德州之星扫描器(We... 透视方针!德州之星扫描器(WePoKer安装包)其实真的是有辅助工具(哔哩哔哩)1、打开软件启动之后...
据悉!微乐小程序黑科技,苹果手... 据悉!微乐小程序黑科技,苹果手机微信小程序游戏破解器(透视)其实真的有辅助攻略(哔哩哔哩)1、上手简...
透视手册!佛手大菠萝有挂吗(德... 透视手册!佛手大菠萝有挂吗(德普之星辅助)其实真的有辅助教程(哔哩哔哩)透视手册!佛手大菠萝有挂吗(...
昨日!微乐小程序黑科技免费,手... 昨日!微乐小程序黑科技免费,手机微乐小程序自建房透视免费(透视)切实真的有辅助工具(哔哩哔哩)暗藏猫...
透视资料!wepoker辅助透... 透视资料!wepoker辅助透视(HHpoker软件)都是存在有辅助神器(哔哩哔哩)1、打开软件启动...
据了解!微乐小程序免费黑科技,... 据了解!微乐小程序免费黑科技,微乐钻石兑换码(透视)确实是有辅助工具(哔哩哔哩)1、点击下载安装,脚...
透视大纲!hhpoker德州真... 透视大纲!hhpoker德州真的假的(WePoKer app)切实是有辅助技巧(哔哩哔哩)1、用户打...