/ / Injectar cliente http no interceptador HTTP Angular 4 - angular, interceptores HTTP-angulares

Injetar cliente http no HTTP Interceptor Angular 4 - angular, interceptores HTTP-angulares

Como posso injetar http client para dentro HTTP Interceptor? Sempre que faço isso, lança: Uncaught Error: Provider parse errors: Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1

Minhas interceptor parece:

@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {

constructor(private ehs: ErrorHandlerService,
private localStorageService: LocalStorageService,
private router: Router,
private http: HttpClient
){}

Respostas:

1 para resposta № 1

Você pode usar Injector

  constructor(inj: Injector) {
this.auth = inj.get(AuthService)
}

Veja este exemplo: https://plnkr.co/edit/8CpyAUSJcCiRqdZmuvt9?p=preview

https://angular.io/api/core/Injector

Longa discussão sobre este assunto aqui: https://github.com/angular/angular/issues/18224