admin管理员组

文章数量:1406926

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.

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.

Share Improve this question asked Aug 28, 2017 at 15:04 Imran LatifImran Latif 1,0239 silver badges23 bronze badges 1
  • What if you have two services that extend Http and add them to the corresponding module's providers; AService to AModule and BService to BModule, Doesn't the service only be applied to coresponding module? – Prav Commented Aug 28, 2017 at 15:13
Add a ment  | 

1 Answer 1

Reset to default 6

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

本文标签: javascriptAngular HTTP Interceptors at Module LevelStack Overflow