0

I have an angular project with lazy loaded modules with Core and shared modules. Each module has some json configuration files that i need to use their contents in the components with dependency injection.

Which walkthrough is better for this:

1- Read json files with a file reader service on loading each module and add the mapped object in DI.
(Can this happen? dynamically read the json file on module loading and inject the object as dependency?)

2- Read json file on loading component and use its data.

3- Other scenarios?

  • Using a provider factory that will return an observable of your config file ? – Gilsdav Aug 04 '20 at 06:54
  • @Gilsdav Seems good idea? imagine read file and it is available for whole module. How can i write one? – Armin Torkashvand Aug 04 '20 at 08:44
  • The core config will be available on each modules but sub-config will only be available on sub modules. Example: `{ provide: 'MAIN_CONFIG', useFactory: (http: HttpClient) => http.get('...'), deps: [HttpClient] }`. Or if you need to access all configs everywhere, you can use a store that will load configs on demand using `NGXS` for example. – Gilsdav Aug 04 '20 at 11:22

0 Answers0