import { Injectable, APP_INITIALIZER } from "@angular/core"; import { HttpClient } from "@angular/common/http"; function getHostUrl() { return '//'+location.host; } @Injectable() export default class ConfigService { public config: any; constructor(private http: HttpClient) { } load(path: string) { return new Promise((resolve, reject) => { this.http.get(getHostUrl()+path) .subscribe(data => { this.config = data; resolve(true); }) }); } static getAppInitializer(path: string) { return { provide: APP_INITIALIZER, useFactory: (config: ConfigService) => () => config.load(path), deps: [ ConfigService ], multi: true }; } }