如何将http client
注入HTTP Interceptor
?每当我这样做时,它会抛出:Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
我的interceptor
看起来像是:
@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {
constructor(private ehs: ErrorHandlerService,
private localStorageService: LocalStorageService,
private router: Router,
private http: HttpClient
){}
答案 0 :(得分:1)
你可以使用注射器
constructor(inj: Injector) {
this.auth = inj.get(AuthService)
}
查看此示例: https://plnkr.co/edit/8CpyAUSJcCiRqdZmuvt9?p=preview
https://angular.io/api/core/Injector
关于这个问题的长篇大论:https://github.com/angular/angular/issues/18224