Angular:如何在后续的Observable中使用`.subscribe()`的结果

前端之家收集整理的这篇文章主要介绍了Angular:如何在后续的Observable中使用`.subscribe()`的结果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Angular2:我想在后续的observable中使用.subscribe()的结果.

这是为了在嵌套订阅中使用来自父订阅的id.

我首先尝试使用.switchMap(),但这似乎不起作用.

这是我的尝试:

this.serviceA.getOrg()
    .switchMap(org => this.serviceB.getOrgType(org.id))
    .subscribe(type => {
        console.log(type);
});

解决方法

试试flatMap:

this.serviceA.getOrg()
    .flatMap(org => this.serviceB.getOrgType(org.id))
    .subscribe(type=> {
      console.log(type);
    });

猜你在找的Angularjs相关文章