I need to load data from a service which contains environment data. I need some of that data for a module in app.modules
.
Here's a small app.modules.ts
example:
import { CustomEnvironmentService } from './CustomEnvironmentService';
let customService: CustomEnvironmentService;
@NgModule({
declarations: [...],
imports: [CustomModule.forRoot(customService.ENVIRONMENT_DATA)],
providers: [...]
})
export class AppModule {}
First thing to notice is that customService.ENVIRONMENT_DATA
is just a public variable in CustomEnvironmentService
which gets information from an environment config file called env.js
.
The problem is that when the app loads customService.ENVIRONMENT_DATA
is undefined. This is understandable as I'm pretty sure the service isn't initialized and hasn't fetched the data.
I found something called APP_INITIALIZER
but it appears that I may not be able to use it to read from either that env.js
file or will it use my CustomEnvironmentService
(which gets the data from env.js
).
I'm also basing my implementation on this article: How to use environment variables to configure your Angular application without a rebuild
Any ideas?