core
core copied to clipboard
Ngx-translate and Angular interceptor?
Hi. I am not sure if this issue was risen. At least, I googled it and found no solution. My app causes Circular dependency when I inject translateService into http interceptor. I googled it and found it's because of HttpClient dependency. The only working solution was to inject Injector and load TranslateService with it. Nevertheless, the error still occurred but the app worked as supposed. Is it any solution for that?
+1
+1
I found a workaround here : https://stackoverflow.com/questions/67152273/angular-circular-dependency-when-inject-translateservice-to-interceptor
You can break the dependency circle by changing HttpLoaderFactory dependency from HttpClient into HttpBackend and by creating new HttpClient.
export function HttpLoaderFactory(httpHandler: HttpBackend) {
return new TranslateHttpLoader(new HttpClient(httpHandler));
}
// ... TranslateModule.forRoot ...
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpBackend] // ←
},