[英]Did Angular 2 have somethings like event when before and after Route's resolver
[英]Is there a way to know, whether a route event DID NOT occur in angular 2?
在代碼塊中,當發生路由器事件以及未發生路由器事件時,我必須有條件地運行一些語句。 我嘗試使用路由器訂閱變量的closed
屬性。 那沒有用。 我想知道是否可以檢測到是否沒有路由器事件,因為如果沒有路由事件是同步的並且即使路由發生更改也要運行(因為這是異步的且幾乎沒有延遲),所以要運行的代碼。
.catch((error: any) => {
if (this.routerSubscription)
this.routerSubscription.unsubscribe();
this.routerSubscription = this._router.events.subscribe(
(event) => {
if (event instanceof NavigationEnd) {
// code if router event occurs
this.routerSubscription.unsubscribe();
}
}
);
// code if no router event occurs
return Observable.throw(error);
});
您可以設置一個標志,以防發生路由器事件,並在完整的回調中檢查是否發生了:
bool wasEvent = false;
this.routerSubscription = this._router.events
.filter(e => event instanceof NavigationEnd)
.first() // take only one
.subscribe(
event => wasEvent = true,
(err) => {},
() => console.log(`Router events happened: ${wasEvents}`)
);
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.