例如,如果我有以下路由组织:
const appRoutes: Routes = [
{
path: "",
component: AppComponent,
resolve: {
app: AppResolver
},
children: [
{
path: "",
component: NestedComponent,
resolve: {
subscribers: NestedResolver
}
}
]
}
];
以及以下解析器:
export class AppResolver implements Resolve<any> {
constructor(private appService: AppService) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return this.appService.getAppData();
}
}
export class NestedResolver implements Resolve<any> {
constructor(private nestedService: NestedService) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
console.log(route.parent.data); //when this is executed route.parent.data is empty :(
return this.nestedService.getNestedData();
}
}
在应用程序引导后,NestedResolver和AppResolver将首先执行并并行发出它们的请求。
我们能否更改代码并实现NestedResolver等待AppResolver解析并访问AppResolver解析的数据?
Angular 2 RC6,Angular路由器3.0.0-rc.2