Reputation: 667
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
){}
Upvotes: 2
Views: 3670
Reputation: 1362
Uou can use Injector
constructor(inj: Injector) {
this.auth = inj.get(AuthService)
}
See this example: https://plnkr.co/edit/8CpyAUSJcCiRqdZmuvt9?p=preview
https://angular.io/api/core/Injector
Long discution about this issue here: https://github.com/angular/angular/issues/18224
Upvotes: 2