Skip to content

Instantly share code, notes, and snippets.

@lydemann lydemann/app.init.ts
Last active Sep 10, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.