Last active
January 5, 2018 15:18
-
-
Save mansour-ahmed/ea564ec044d839e7a4e82843d2e8af8e to your computer and use it in GitHub Desktop.
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
/** | |
* @desc ConfigService will be used to deal with loading and saving config files that is needed to init the app | |
*/ | |
import { Injectable } from '@angular/core'; | |
import { Http } from '@angular/http'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/add/operator/toPromise'; | |
@Injectable() | |
export class ConfigService { | |
// data; | |
private configs: any; | |
constructor(private http: Http) { } | |
/** | |
* @desc load Fn loads the config file form the assets and save it to local storage. | |
* Important: It should return a Promise. | |
*/ | |
public load(): Promise<any> { | |
this.configs = null; | |
return this.http.get('assets/config.json').map((res) => res.json()) | |
.toPromise() | |
.then((config) => { | |
// your configs are here in your app's state for instance in ngrx store's state. | |
}) | |
.catch((err: any) => Promise.resolve()); | |
} | |
get configData(): any { | |
return this.configs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment