Last active
September 10, 2018 09:43
-
-
Save lydemann/02e0c8a68d3ec413bf41c27deba9f4e9 to your computer and use it in GitHub Desktop.
App init for getting dynamic configuration on app startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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