【发布时间】:2017-06-19 20:08:51
【问题描述】:
我想进行一次 HTTP 调用,然后根据其结果可能将其替换为另一个。这是 Angular。
this.http.get('foo.txt')
.map(response => response.text())
.if(text => text === "TRYAGAIN",
this.http.get('bar.txt').map(response => response.text()))
.subscribe(text => console.log("got text", text);
但是虽然有一个if 操作符,但这里似乎并没有做我想要的。
我考虑过(错误地)使用错误来做到这一点:
this.http.get('foo.txt')
.map(response => response.text())
.map(text => {
if (text === "TRYAGAIN") throw "";
return text;
})
.catch(err => this.http.get('bar.txt').map(response => response.text()))
.subscribe(text => console.log("got text", text);
但这似乎也不理想。处理这种情况的正确成语是什么?
【问题讨论】:
标签: rxjs angular2-http