【发布时间】:2018-11-10 13:30:49
【问题描述】:
我对服务器有两个Observable 请求:
this.initService.__init__(res).subscribe((profile) => {
console.log(profile); // It works
this.initService.initializePeriod(profile).subscribe((period) => {
console.log(period); // It does not work
});
});
当第一次得到响应时,它调用第二个,但我无法获得第二个订阅的结果。我知道,在这种情况下最好使用 Promises,但我需要将结果从第一个请求传递到第二个请求,promises 不允许这样做。
我尝试使用它,但警报消息不起作用:
this.initService.__init__(res)
.pipe(
mergeMap(profile => this.initService.initializePeriod(profile)))
.subscribe((response) => {
alert('aa');
});
也试过这个:
this.initService.__init__(res)
.mergeMap(profile => this.initService.initializePeriod(profile))
.subscribe((response) => {
alert('aa');
});
【问题讨论】: