Hi all,
I have a question for you. I should load an external file, a JSON file, containing environment variables.
For example:
export class ClientService {
...
checkMail(...): any {
return this.http.post(`${this.conf.hostServer}/api/otp`, ...)
}
In this case I have
this.conf.hostServer that must be read from another class.
@Injectable()
export class ConfigService {
env: string
constructor(public http: HttpClient) {
this.setSocketServer();
}
setSocketServer() {
return new Promise<boolean>((resolve: (a: boolean) => void): void => {
this.http.get('./config.json').pipe(map((x: any) => {
this.env = x.env;
resolve(true);
}))
.subscribe();
});
}
}
In this way I have in my ClientService the correct variables but I have to wait in my components that they are ready.
How can I do this ?
I saw that is present another way using APP_INITIALIZE but I don't like it for this case.
What do you suggest me ?
Thanks.