To do this, you can use the JSON configuration file and upload it using HTTP. In this case, you can download your application asynchronously to wait for the configuration data to load. Here is an example:
let appProviders = [ HTTP_PROVIDERS, ConfigurationService ];
var app = platform(BROWSER_PROVIDERS)
.application([BROWSER_APP_PROVIDERS, appProviders]);
let service = app.injector.get(ConfigurationService);
service.getConfiguration().flatMap((configuration) => {
var configurationProvider = new Provider('configuration', { useValue: configuration });
return app.bootstrap(AppComponent, [ configurationProvider ]);
}).toPromise();
A class ConfigurationServicecould be something like this:
@Injectable()
export class ConfigurationService {
constructor(private http:Http) {
}
getConfiguration() {
return this.http.get('config.json').map(res => res.json());
}
}
See this question for more information:
source
share