如何使用Angular中的RXJ启用数据,直到收到数据,直到收到数据
有一个API,已发送HTTP请求,并且很长一段时间没有响应,但是当用户刷新页面时,API会直接响应此行为,因此我想使用RXJS克服此问题。当API在40秒内未响应时,应自动重试HTTP请求&应该尝试3次。如何使用RXJ
在这里实现此行为是代码:
abc.service.ts
getABC() {
return this.http
.get(.........)
.pipe(
map(responseData => {
return responseData
}),
catchError(errorRes => {
return this.handleError(errorRes);
})
);
}
xyz.component.ts
this._abcService.getABC().subscribe((res: any[]) => {
console.log(res);
}, error => {
console.log(error);
});
帮助我解决这个问题
There is an API where the HTTP request has been sent and there is no response for a long time but when the user refreshes the page the API responds immeditally this behavior occurs often, so I want to use RXJS to overcome this issue. when the API does not respond within 40 seconds it should automatically retry the HTTP request & it should be attempted 3 times. how to achieve this behavior using RXJS
Here is the code:
ABC.service.ts
getABC() {
return this.http
.get(.........)
.pipe(
map(responseData => {
return responseData
}),
catchError(errorRes => {
return this.handleError(errorRes);
})
);
}
XYZ.component.ts
this._abcService.getABC().subscribe((res: any[]) => {
console.log(res);
}, error => {
console.log(error);
});
Help me with this Issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看在此处发布的解决方案:
https://stackoverflow.com/a/50678363/2976617
需要调整超时的时间和重试的数量。
Please have a look at the solution already posted here:
https://stackoverflow.com/a/50678363/2976617
You only need to adjust the time for the timeout and the number of retries.