简体   繁体   中英

Angular HTTP Interceptors at Module Level

I just upgraded my Angular v4.2.5 app to Angular v4.3.6 primarily to use Interceptors . It is quite an awesome feature and provides a clean way to intercept HTTP calls.

However, it seems I cannot scope interceptors at modules level. For example, I have an AppModule , and two more modules AModule and BModule . Both AModule and BModule are getting included in AppModule .

Now, is there a way in Angular 4 where I can scope interceptors at module level such that an interceptor I use for HTTP requests in AModule shouldn't be used with HTTP requests in BModule . Presently, interceptors are getting shared across all HTTP calls which was not I expected. I know providers from all modules get merged into the parent module, but is there any way to restrict such thing?

Any help is highly appreciated.

Add a header or flag to the request from the different services? And then use this to delineate where it is from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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