我有一条路线:
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']
传递给mySecondResolver
mySecondResolver
取决于price
属性{ {1}}。如何将结果从obj
传递给myFirstResolver
?
答案 0 :(得分:0)
您可以将两个解析器合并到一个解析器中并将它们链接起来:创建ThirdResolver,然后导入其他两个解析器并将它们的resolve
方法链接在一起。