Skip to content

Instantly share code, notes, and snippets.

@mansour-ahmed
Last active January 5, 2018 15:18
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 mansour-ahmed/ea564ec044d839e7a4e82843d2e8af8e to your computer and use it in GitHub Desktop.
Save mansour-ahmed/ea564ec044d839e7a4e82843d2e8af8e to your computer and use it in GitHub Desktop.
/**
* @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