/ / Inyectar el cliente http en el Interceptor HTTP Angular 4: interceptores angulares, angulares-http

Inyecte el cliente http en el Interceptor HTTP Angular 4: interceptores angulares, angulares-http

Cómo puedo inyectar http client dentro HTTP Interceptor? Cada vez que lo hago, arroja: Uncaught Error: Provider parse errors: Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1

Mi interceptor parece:

@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {

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

Respuestas

1 para la respuesta № 1

Uou puede usar Inyector

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

Mira este ejemplo: https://plnkr.co/edit/8CpyAUSJcCiRqdZmuvt9?p=preview

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

Larga discución sobre este tema aquí: https://github.com/angular/angular/issues/18224