How to use two instances of HttpClient (one with 2 interceptors and the other one with 1 interceptor) in Angular 4.3?

Viewed 1157

In our Angular 4.3 project, we have public-site components and secured-site (logged in) components separately. We use @angular/common/http. We want to implement different http interceptors for public-site components and secured-site components. For example,

  1. public-site components - to apply only below interceptor
    LoggingInterceptor
  2. secured-site components - to apply below two interceptors
    LoggingInterceptor
    AuthTokenInterceptor (to pass the auth token in request header)

We tried adding providers details HTTP_INTERCEPTORS at each component level @Component with different interceptors. But the request is not going into any of the interceptors.

The request is going into interceptors only if we add the providers details HTTP_INTERCEPTORS in @NgModule. Here the problem is, public site http requests also go into AuthTokenInterceptor which is not needed.

So how should we solve this? Thanks.

1 Answers
Related