avdeveloper
avdeveloper

Reputation: 549

How to call Method where Constructor has httpclient in @NgModule?

I am currently using Transloco to do translation in my application. I have the below @NgModule.

@NgModule({
  exports: [TranslocoModule],
  providers: [
    {
      provide: TRANSLOCO_CONFIG,
      useValue: translocoConfig({
        availableLangs: MyService().getLanguages(),
        defaultLang: 'en',
        fallbackLang: 'en',
        reRenderOnLangChange: true,
        prodMode: environment.production,
      })
    },
    { provide: TRANSLOCO_LOADER, useClass: TranslocoHttpLoader }
  ]
})

MyService class makes a call to an external API and it has HttpClient in it's constructor. I want to be able to set the parameter availableLangs by calling getLanguages() and injecting HttpClient in the MyService(...). The problem is I cannot find a way to inject dependencies in the @NgModule.

Is this possible or are there any alternatives?

Upvotes: 0

Views: 492

Answers (1)

Drenai
Drenai

Reputation: 12397

You should look into using Angular APP_INITIALIZER - and load the language data before the application starts up

Upvotes: 0

Related Questions