V
V
ValeraValera2019-04-12 12:04:16
JavaScript
ValeraValera, 2019-04-12 12:04:16

How to take a function out of app.module and inject a service into it to get settings?

there is such function in app.module.ts

export function exportTranslateStaticLoader(http: HttpClient, transferState: TransferState, cookie: CookieService) {
  let apiUrl;
  if (environment.browser.symphonyApiUrl) {
    apiUrl = environment.browser.symphonyApiUrl;
  } else {
    const protocol = window.location.protocol;
    const host = window.location.host;
    apiUrl = `${protocol}//api.${host}`;
  }
  const link = environment.remoteTranslate ? `${apiUrl}/cms/locale/` : '/assets/i18n/';
  return new TranslateBrowserLoader(link, '.json', transferState, http, cookie);
}

further in the imports block, it is used as follows
TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: exportTranslateStaticLoader,
        deps: [HttpClient, TransferState, CookieService]
      }
    }),

it uses the values ​​from the environment.ts file which is a simple object and is imported into the app.module
i need to get the values ​​not from the environment file but from the service, but i can't use the service in app.module
how to properly remove this function from app.module so that you can use the app-config.service service in it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question