2
我有在名爲/輔助路線加載的側欄的組成部分。這工作正常。在Angular2,如何可以動畫,其在輔助路線加載的組件?
另外,我有在該組分中的元數據的一些動畫設置,用於在效果的幻燈片。這部動畫也能正常工作,當我點擊一個按鈕,當加載該組件「正常」,例如。
然而,當我在一個輔助的路線加入這種成分,動畫不會觸發。該組件即刻呈現。
爲什麼?我怎樣才能解決這個問題?見下面的代碼。
sidebar.component.ts
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'sidebar',
templateUrl: 'sidebar.component.html',
styleUrls: ['sidebar.component.scss'],
animations: [trigger('slideIn', [
state('false', style({
width: '0'
})),
state('true', style({
width: '18.75rem'
})),
transition('0 => 1', animate('300ms ease-in')),
transition('1 => 0', animate('300ms ease-out'))
])]
})
export class SidebarComponent {
shouldAnimate: boolean;
constructor(private route: ActivatedRoute){
if (this.route.outlet === 'sidebar') {
this.shouldAnimate = true; // Yes, I do enter here every time
}
}
}
從app.routes.ts sidebar.component.html
<div id="sidebar"
[@slideIn]="shouldAnimate">
</div>
{ path: 'profile', outlet: 'sidebar', component: SidebarComponent }
從app.component.ts
<router-outlet name="sidebar"></router-outlet>
Weblurk發現「空白」的榮譽。你爲我節省了很多時間。 – codeepic