core icon indicating copy to clipboard operation
core copied to clipboard

Ngx-translate and Angular interceptor?

Open Triplecorpse opened this issue 3 years ago • 5 comments

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?

Triplecorpse avatar Jun 21 '21 17:06 Triplecorpse

+1

saghishiri avatar Sep 23 '21 14:09 saghishiri

+1

yassinumer avatar Sep 26 '21 14:09 yassinumer

I found a workaround here : https://stackoverflow.com/questions/67152273/angular-circular-dependency-when-inject-translateservice-to-interceptor

yassinumer avatar Sep 26 '21 14:09 yassinumer

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] // ←
},

hozikm avatar Nov 15 '22 14:11 hozikm