2017-06-02 124 views
0

我有一個路線:角路由器嵌套解析(S)

const routes: Routes = [ 
    { 
     path: ':id', 
     component: MoyComponent, 
     resolve: { 
      first: MyFirstResolver 
      second: mySecondResolver(first) 
     } 
    } 

我有一個解析器:

@Injectable() 
export class MyFirstResolver implements Resolve<any> { 
    constructor(private ms: MyService, private router: Router) {} 
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> { 
     let id = route.params['id']; 
     return this.ms.get(id).map(res => { 
      if (res) { 
       return res; 
      } else { 
       this.router.navigate(['/']); 
       return null; 
      } 
     }); 
    } 
} 

MyFirstResolver返回一個對象obj,我想傳遞obj['price']mySecondResolvermySecondResolver取決於objprice財產。我怎樣才能將結果從myFirstResolver傳遞到mySecondResolver

+1

你有兩個'return語句' – Aravind

+0

我不明白@Aravind – Moshe

+0

你可能需要將它們合併到它自己的解析器中。理論上講,你可以簡單地創建一個ThirdResolver類,導入前兩個,並將它們鏈接在一起。 – wilsonhobbs

回答

1

您可以將兩個解析器合併爲一個解析器並鏈接它們:因此創建ThirdResolver並導入其他兩個解析器並將它們的方法鏈接在一起。