I use ngx-translator for localization. When I am trying to read json-files with localization that stores in local folder, I receiving an error HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http:/host.com/api/assets/i18n/en.json", ok: false, …}. I thing that problem is in Interceptor that I use in my app.
// app.module.ts
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
}
How can I disable interceptor in this function? I tried to set header as X-Skip-Interceptor, but It doesn't help.
You can use HttpBackend
When injected, HttpBackend dispatches requests directly to the backend, without going through the interceptor chain.
In your app.module.ts pass HttpBackend as deps and not HttpClient
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (HttpLoaderFactory),
deps: [HttpBackend],
},
}),
And Modify HttpLoaderFactory as below
export function HttpLoaderFactory(handler: HttpBackend) {
const http = new HttpClient(handler);
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With