【发布时间】:2017-09-25 07:24:38
【问题描述】:
我正在尝试使用 Angular/4 在 Angular CLI 项目中实现路由动画。我一直在尝试遵循 this 教程,但收效甚微。
我的代码读取
/src/app/_animations/fadein.animation.ts
import { trigger, state, animate, transition, style } from '@angular/animations';
export const fadeInAnimation =
// trigger name for attaching this animation to an element using the
[@triggerName] syntax
trigger('fadeInAnimation', [
// route 'enter' transition
transition(':enter', [
// css styles at start of transition
style({ opacity: 0 }),
// animation and styles at end of transition
animate('3000ms', style({ opacity: 1 }))
]),
]);
/src/app/dashboard/dashboard.component.ts
import { Component, OnInit } from '@angular/core';
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';
// import fade in animation
import { fadeInAnimation } from './../_animations/fadein.animation';
import { PickJob } from './../pick-jobs/pick-job';
import { PickJobService } from './../pick-jobs/pick-job.service';
import { FlashService } from './../flash/flash.service';
@Component({
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css'],
animations: [fadeInAnimation],
host: { '[@fadeInAnimation]': '' }
})
export class DashboardComponent {}
/src/app/dashboard/dashboard.component.html
<div class="container_flex">
<div class="row">
<div class="col-md-12">
<div class="btn btn-block btn-primary block shadow">
Print Next Pick Job
</div>
<a class="btn btn-block btn-danger shadow" routerLink="/pick-jobs" routerLinkActive="menu-active">
List Pick Jobs
</a>
<a class="btn btn-block btn-warning shadow" routerLink="/cages/assign" routerLinkActive="menu-active">
Print Pick Cage Labels
</a>
</div>
</div>
</div>
/src/app/app.module.ts
...
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
...
@NgModule({
imports: [
...
BrowserAnimationsModule,
...
动画从不运行,在页面加载之前完成。不确定是哪个。有人能在我的代码中发现错误吗?非常感谢任何建议
【问题讨论】:
-
你能创建一个 plunker 吗?
-
请注意,正在更改路线动画(假设为 4.1,现在将更新)以解决此类问题,因此您应该很快就会看到有关这些事情的更多信息。跨度>
-
您浏览过文档吗? angular.io/guide/…。您正在使用的教程根据其日期显示是最近的,但它仍然过时,因为他使用的是主机元数据而不是 @HostBindings
-
另外,这是一些Angular动画眼睛糖果slides.yearofmoo.com/ng-japan-2017-demo,您可以查看相关幻灯片slides.yearofmoo.com/ng-japan-2017-slides/#/0/0,其中包含路线动画信息
-
如果您使用的是 Angular Material,请查看或观看此问题,这似乎会阻止在 v4.2.2 中出现github.com/angular/material2/issues/5107 的路线动画