我已经实现了
HttpInterceptor接口,以拦截传出请求和传入响应.
我想在创建请求时显示加载程序,并在收到响应时隐藏该加载程序.
虽然代码波纹管在检测到HttpResponse时起作用,但它没有检测到Http Failure(当响应代码不同于200时),因此加载器不会被隐藏.
@Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private loaderService: LoaderService) { } intercept(req: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> { this.loaderService.show(); return next .handle(req) .do(event => { //nothing is printed when a Http failure occurs console.log('detecting event ',event); if (event instanceof HttpResponse) { console.log('detecting http response'); this.loaderService.hide(); } }); } }