Skip to content

Instantly share code, notes, and snippets.

@lydemann
Last active September 10, 2018 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/02e0c8a68d3ec413bf41c27deba9f4e9 to your computer and use it in GitHub Desktop.
Save lydemann/02e0c8a68d3ec413bf41c27deba9f4e9 to your computer and use it in GitHub Desktop.
App init for getting dynamic configuration on app startup
import { Injectable } from '@angular/core';;
import { from } from 'rxjs';
import { filter, map, switchMap, tap } from 'rxjs/operators';
declare var window: any;
@Injectable()
export class AppInitService {
// This is the method you want to call at bootstrap
// Important: It should return a Promise
public init() {
return from(
fetch('assets/app-config.json').then(function(response) {
return response.json();
})
).pipe(
map((config) => {
window.config = config;
return
})).toPromise();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment