例如,如果我有以下路线组织:
const appRoutes: Routes = [ { path: "",component: AppComponent,resolve: { app: AppResolver },children: [ { path: "",component: NestedComponent,resolve: { subscribers: NestedResolver } } ] } ];@H_404_3@和以下解析器:
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(); } }@H_404_3@应用程序引导后,NestedResolver和AppResolver将首先执行并并行发出请求. @H_404_3@我们可以更改代码并实现NestedResolver等待AppResolver解析并可以访问AppResolver解析数据吗? @H_404_3@Angular 2 RC6,Angular router 3.0.0-rc.2
我知道这个问题很老了,以防万一有人偶然发现它(像我一样).
@H_404_3@这是一个已知的错误,它已被修复.只需将您的路由器版本更新为高于或等于2.1.0的版本,您应该好好去.这里参考的是相关的issue on github和associated fix