大佬教程收集整理的这篇文章主要介绍了Angular 4 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(); } }); } }
以上是大佬教程为你收集整理的Angular 4 HttpInterceptor:显示和隐藏加载器全部内容,希望文章能够帮你解决Angular 4 HttpInterceptor:显示和隐藏加载器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。