角度路由器嵌套解决方案

时间:2017-06-02 20:49:47

标签: angular angular-routing

我有一条路线:

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

1 个答案:

答案 0 :(得分:0)

您可以将两个解析器合并到一个解析器中并将它们链接起来:创建ThirdResolver,然后导入其他两个解析器并将它们的resolve方法链接在一起。