最近Angular2でプレイを開始しました。 は、私はこのようなリゾルバを使用することを開始しました:Angular2キャンセル経路の変更(非同期リゾルバを使用している場合)
export class LoaderComponent {
@HostBinding('class.active') active:boolean = false;
constructor(private router: Router, private location: Location) {
router.events.subscribe(this.handleRouteChange.bind(this));
}
onCancelButtonClicked() {
this.active = false;
//Any idea?
}
private handleRouteChange(event: Event) {
if (event instanceof NavigationStart) {
console.log('START');
this.active = true;
} else
console.log('END');
this.active = false;
}
}
}
がthis.api.get('days')
がゆっくり実行していることを想像して、あなたがしたい:私は基本的なローダコードを実装
export class SomeResolver implements Resolve<[Day]> {
constructor(private api: API) {}
resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):Observable<any> {
return this.api.get('days')
}
}
この問題を解決する方法はありますか?
チェック[この](http://stackoverflow.com/questions/39061623/how-to-cancel-route-change -in-angular-2)、それが助けてくれることを願っています! –
返信いただきありがとうございます!私はresolverが彼の仕事を始める前にcanを失効させることを恐れている。これは実際に問題を解決するものではありません:( –