简体   繁体   English

通过在 Angular 中拦截 http req 获取组件级别的微调器/进度条

[英]Get spinner/progress bar on component level by intercepting http req in Angular

I have a requirement where I need to display spinner (or) progress bar on component level.我有一个要求,我需要在组件级别显示微调器(或)进度条。 Each of these components call different end-points.这些组件中的每一个都调用不同的端点。

I followed few approaches suggested below but they intercept all the http-requests.我遵循了下面建议的几种方法,但它们拦截了所有 http 请求。 How to go about intercepting these requests on component level and display spinners? go 如何在组件级别拦截这些请求并显示微调器?

https://medium.com/@deniscangemi/intercept-http-requests-in-angular-c6392b7b0e0 https://medium.com/@deniscangemi/intercept-http-requests-in-angular-c6392b7b0e0

https://medium.com/@zeljkoradic/loader-bar-on-every-http-request-in-angular-6-60d8572a21a9 https://medium.com/@zeljkoradic/loader-bar-on-every-http-request-in-angular-6-60d8572a21a9

If you are going the Http interceptor route, then you can just take advantage of using either an event emitter and then listen for messages related to the call you are checking for.如果您要使用 Http 拦截器路由,那么您可以利用任一事件发射器,然后侦听与您正在检查的呼叫相关的消息。 Another thing you can do would be to have a service that you set in the interceptor, but also you can listen for you the component.您可以做的另一件事是在拦截器中设置一个服务,但您也可以监听组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM