Angular2アプリでページ遷移を手動で実行したいと思います。私がこれまで行ってきたことは、ナビゲーションを扱うComponentから呼び出すサービスです。リンクをクリックするかアイコンか何かを呼び出すと、AnimationService goTo
メソッドと呼ばれます。これはURLを受け取り、Observableストリーム/サブジェクトにプッシュします。ここでは、これまでのサービスは以下のとおりです。Angular2とReactiveでCSSアニマートの終わりを聞く方法
@Injectable()
export class AnimationService {
// should you be a directive?
animationStream: Subject<string> = new Subject<string>();
animationStreamEnd:Subject<string> = new Subject<string>()
constructor() {
// this is to listen for when it is time to navigate to whereever?
this.animationStreamEnd.subscribe(resp => {
// redirect the url/app here
this.router.go(resp);
});
}
goTo(url:string): void {
// so, broadcast down to trigger the css animation...
this.animationStream.next(url);
}
}
私はアニメーション化したいコンテンツがそれでngClass
条件は、それがこの
<div class="gridClass" [ngClass]="{'animate-left': applyTransitionClass}">
<div class="gridRow">
<route-view></route-view>
</div>
</div>
</div>
ようになりますし、それに、そう[ngClass]="{'animate-left': applyTransitionClass}"
のようなHTMLテンプレートのコンポーネントIのしています私が観察し、どのように私は、CSSアニメーションをトリガー値を変更するに加入どこあなたが見ることができ、次のコード
export class AnotherComponent {
constructor(private animationService: AnimationService) {
public applyTransitionClass: boolean = false;
this.animationService.animationStream.subscribe(resp => {
// resp is a url...
// apply a css class... when that is done we need to broadcast the thing is done...
this.applyTransitionClass = true;
// here I want to listen for when the animation end (it is only 1 second) and tell the animationService to now navigate to wherever
this.animationService.animationStreamEnd.next(resp);
});
}
を持っています。今度はコンポーネント内で、私がちょうどトリガーしたCSSクラスの終わりを聞きたいのですが、AnimationServiceに、これがアニメーションストリームにプッシュすることによって起こったことを知らせてください。しかし、私はアニメーション終了イベント(例えば、"transitionend","oTransitionEnd","transitionend","webkitTransitionEnd"
のようなもの)を取得する方法を知らない。私はちょうど1秒遅れを設定することができますが、Observablesを使用したいと思います。
私は自分自身についてよく説明していないことを知っています。要件を明確にするために必要な場合は、問題を修正します。前もって感謝します。
問題は、(Angular2アニメーションをパラメータ化することができないので、ありますまだ)、それらを使用することはできませんすべてのトランジション。 –