0

I am trying to setup baseHref for my angular app dynamically. Additionally the final baseHref is stored in config.json in different location so I have to make a http request for that, but how Can I do that in module?

Now, my app.module.ts looks like this:

@NgModule({
  ...
  providers: [        
    {
      provide: APP_BASE_HREF,
      useValue: '/path/'
    },
  ...
})

How can I simply update useValue field with every page refresh and additionally get this value from http request.

johnek smith
  • 33
  • 1
  • 8
  • Does that help? https://stackoverflow.com/questions/38112891/angular-2-4-5-set-base-href-dynamically/41949470 – David Jun 20 '19 at 13:23
  • Nope, I can't use 'window' in app.module.ts because it's angular-universal and this solution don't include external `baseHref` from another config file. – johnek smith Jun 20 '19 at 13:48
  • Maybe use the `APP_INITIALIZER` token to retrieve the config file first, and then use the value to provide `APP_BASE_HREF` ? – David Jun 21 '19 at 07:32
  • @David good idea, now I can get expected value using `APP_INITIALIZER` and some additional service, but how can I pass this variable to `useValue` field of `APP_BASE_HREF`? – johnek smith Jun 21 '19 at 11:52
  • Maybe set a global variable with the wanted value when providing the `APP_INITIALIZER_TOKEN`, then use that value with `useValue` when providing `APP_BASE_HREF `( or try`useFactory` if `useValue` does not work) – David Jun 21 '19 at 12:07

0 Answers0