Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @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