If you want to incorporate a JSON configuration file into your project, one approach is to retrieve it via HTTP and use it to bootstrap your application asynchronously. Here's an example implementation:
const appModules = [ HTTP_MODULES, ConfigurationService ];
const appInstance = platform(BROWSER_MODULES)
.application([BROWSER_APP_MODULES, appModules]);
const configService = appInstance.injector.get(ConfigurationService);
configService.fetchConfig().flatMap((configData) => {
const configProvider = new Provider('config', { useValue: configData });
return appInstance.bootstrap(AppComponent, [ configProvider ]);
}).toPromise();
The ConfigurationService
module may look like this:
@Injectable()
export class ConfigurationService {
constructor(private http:Http) {
}
fetchConfig() {
return this.http.get('configuration.json').map(res => res.json());
}
}
For more information, check out the following question:
- Angular Bootstrap with AJAX Data Loading