我試圖用角/ 4以實現在角CLI項目路線的動畫。我一直在試圖遵循this教程,但成效有限。角/ 4 - 路線的動畫不工作
我的代碼讀取
/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嗎? – Aravind
爲了解決這樣的問題,只需簡單地說一下路由動畫正在改變(假設爲4.1,現在將在以後),所以你應該很快看到關於這些事情的更多信息。 – chrispy
您是否瀏覽過文檔? https://angular.io/guide/router#adding-animations-to-the-routed-component。您正在使用的教程近期基於其日期顯示,但由於他使用的是主機元數據,而且它仍然過時,而不是@HostBindings – mtpultz