2016-09-07 5 views
8

を:角度2つのネストされたルートの解決の実行たとえば

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が最初に実行され、t相続人の要求を並行して行う。

私たちはコードを変更して、NestedResolverがAppResolverが解決するのを待って、AppResolverの解決済みデータにアクセスできることを実装できますか?

角度2 RC6、角度ルータ3.0.0-rc.2

+1

この回答を見つけられましたか? –

答えて

3

私はこの質問はかなり古いです知っているが、念のために誰かが(私のように)それつまずきます。

これは既知のバグであり、修正されています。あなたのルーターのバージョンを2.1.0以上のものにアップデートするだけで良いです。参考のために関連するissue on githubassociated fix

関連する問題