我在 Angular 5 中使用 HTTPInterceptor 功能。它在克隆 http 请求并发送到服务器(后端服务器)时按预期工作。我只从 HTTPInterceptor 显示和隐藏应用程序加载器,这也工作正常,但我对一个 GET 请求使用了轮询,该请求每 5 秒从后端服务器获取数据,这让用户感到恼火。那么,有没有办法检查 HTTPInterceptor 中的特定请求?并且也不允许根据该请求显示/隐藏加载程序。
以下是拦截函数的当前代码片段:
intercept (req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.loadingIndicatorService.showLoader();
this.customAuthorizationHeader();
const apiRequest = req.clone({headers:this.headers});
return next.handle(apiRequest).do
((response) => {
if (response instanceof HttpResponse) {
this.loadingIndicatorService.hideLoader();
}
},
(error) => {
this.loadingIndicatorService.hideLoader();
});
};Run Code Online (Sandbox Code Playgroud)
提前致谢。