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

相关内容

热门资讯

揭秘关于!微乐自建房辅助工具脚... 揭秘关于!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)方法1、每一步都需要思考,不同水...
我来教大家!微乐小程序自建房辅... 我来教大家!微乐小程序自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)攻略小薇(辅助器软件下载...
一分钟了解!微乐家乡麻将自建房... 一分钟了解!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)方法1、一分钟了解!微...
揭秘一下!微信雀神麻将挂件开挂... 揭秘一下!微信雀神麻将挂件开挂辅助,微乐自建房脚本免费入口(开挂自建房)技巧微信雀神麻将挂件开挂辅助...
一分钟揭秘!微乐自建房辅助工具... 一分钟揭秘!微乐自建房辅助工具挂,微乐自建房脚本免费入口(开挂自建房)软件1、下载好微乐自建房辅助工...
盘点一款!微信卡五星辅助器,微... 盘点一款!微信卡五星辅助器,微乐家乡麻将自建房辅助app(开挂自建房)插件1、玩家可以在微乐家乡麻将...
六分钟了解!微乐小程序自建房辅... 六分钟了解!微乐小程序自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)工具微乐小程序自建房辅助...
记者爆料!微乐家乡麻将自建房辅... 记者爆料!微乐家乡麻将自建房辅助app,微乐小程序免费黑科技(开挂自建房)工具1、玩家可以在微乐家乡...
终于清楚!微乐自建房辅助工具神... 终于清楚!微乐自建房辅助工具神器,微乐家乡麻将自建房辅助app(开挂自建房)插件1、很好的工具软件,...
必看攻略!微信卡五星辅助器,微... 必看攻略!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)脚本1、微信卡五星辅助器免费脚本咨询教...