How can I inject http client into HTTP Interceptor? Whenever I do it, it throws: Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
My interceptor looks like:
@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {
constructor(private ehs: ErrorHandlerService,
private localStorageService: LocalStorageService,
private router: Router,
private http: HttpClient
){}
new HttpClient(arrayOfHttpInterceptors). When you try to inject the HttpClient into one of the interceptors it can't work, because both client and interceptor would have to wait for the other one to be built first. However, you can get either during runtime through the injector, because they do not mutually depend on each other during instantiation.