angular 如果 http 请求失败,间隔停止
angular interval stops if http request fails
我在我的 ionic 4 应用程序中使用间隔 angular
我的代码是:
interval(10000)
.pipe(
flatMap(() => this.getNotifications())
)
.subscribe(data =>
console.log(data)
);
getNotifications() {
const body = 'x=1';
return this.http.post('http://localhost/fsrownerappapi/printer/orderrequest', body)
.pipe(map((response: any) => response));
}
通过这段代码应用程序在 10 秒的时间间隔内连续执行 http 请求。
如果任何 http 请求失败,它将停止在该时间间隔内连续执行 http 请求。
任何人都可以告诉我如何在任何 http 请求失败的情况下继续该请求吗?
您应该在服务 (getNotifications) 上添加一个 catchError。
this.httpClient.get(url)
.pipe(
map((res: any) => {}),
catchError(this.handleError);
)
我在我的 ionic 4 应用程序中使用间隔 angular 我的代码是:
interval(10000)
.pipe(
flatMap(() => this.getNotifications())
)
.subscribe(data =>
console.log(data)
);
getNotifications() {
const body = 'x=1';
return this.http.post('http://localhost/fsrownerappapi/printer/orderrequest', body)
.pipe(map((response: any) => response));
}
通过这段代码应用程序在 10 秒的时间间隔内连续执行 http 请求。 如果任何 http 请求失败,它将停止在该时间间隔内连续执行 http 请求。
任何人都可以告诉我如何在任何 http 请求失败的情况下继续该请求吗?
您应该在服务 (getNotifications) 上添加一个 catchError。
this.httpClient.get(url)
.pipe(
map((res: any) => {}),
catchError(this.handleError);
)