Angular 我可以在Rxjs重试时更改查询参数值吗?
我的服务最初返回null(初始化后台作业)Angular 我可以在Rxjs重试时更改查询参数值吗?,angular,rxjs,rxjs5,Angular,Rxjs,Rxjs5,我的服务最初返回null(初始化后台作业)[this.q=true]。但稍后如果我将其更改为[this.q=false],如果作业成功,它将返回值 因此,首先我需要调用[this.q=true]并重试[this.q=false]。 但是下面的代码不起作用。它总是让人兴奋 Retry重新订阅源可观测值,因此,如果您想更改Retry上的get请求的参数,您应该将参数值的计算作为源可观测值的一部分。例如 return Observable.of('https://api.example.com?q='
[this.q=true]
。但稍后如果我将其更改为[this.q=false]
,如果作业成功,它将返回值
因此,首先我需要调用[this.q=true]
并重试[this.q=false]
。
但是下面的代码不起作用。它总是让人兴奋
Retry
重新订阅源可观测值,因此,如果您想更改Retry
上的get
请求的参数,您应该将参数值的计算作为源可观测值的一部分。例如
return Observable.of('https://api.example.com?q=')
.concatMap((baseUrl) => this.http.get(baseUrl + this.q))
.map((res: any) => {
if (res === null) {
throw new Error("not enough tiles !");
}
return res;
}).catch((e) => {
this.q = false;
return error;
})
.retryWhen(e => e.delay(2000))
.retry(3);
在“catch”中有这个.q=false,而不是在if(res==null){this.q=true;…}中。响应null可能有效响应null有效这就是为什么我在
res===null时抛出错误,从而将控件发送到catch中。我放了控制台,它被执行了。第一个请求https://api.example.com?q=true
,它将返回null。之后,我必须使用https://api.example.com?q=false
。我认为抛出新错误(“..”)不会使程序进入“catch”,但我不确定,甚至只是可观察。延迟(()=>this.http.get()https://api.example.com?q=${this.q}')),映射(…).catch(…).retryWhen(…)。重试(3)
而不是().concatMap
return Observable.of('https://api.example.com?q=')
.concatMap((baseUrl) => this.http.get(baseUrl + this.q))
.map((res: any) => {
if (res === null) {
throw new Error("not enough tiles !");
}
return res;
}).catch((e) => {
this.q = false;
return error;
})
.retryWhen(e => e.delay(2000))
.retry(3);