如何将http客户端
注入(inject)HTTP拦截器
?每当我这样做时,它都会抛出:未捕获错误:提供程序解析错误:
无法实例化循环依赖! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): 在 ./AppModule@-1:-1 中的 NgModule AppModule
我的拦截器
看起来像:
@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {
constructor(private ehs: ErrorHandlerService,
private localStorageService: LocalStorageService,
private router: Router,
private http: HttpClient
){}
最佳答案
你可以使用注入(inject)器
constructor(inj: Injector) {
this.auth = inj.get(AuthService)
}
看这个例子: https://plnkr.co/edit/8CpyAUSJcCiRqdZmuvt9?p=preview
关于angular - 将http客户端注入(inject)HTTP拦截器Angular 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47619063/