Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Observable } from 'rxjs/Observable';
- import 'rxjs/add/operator/catch';
- import 'rxjs/add/operator/map';
- import { Http } from '@angular/http';
- @Injectable()
- export class Config {
- private _config: Object;
- private _env: Object;
- constructor(private http: Http) {}
- load() {
- console.log('Load configuration...');
- return new Promise((resolve, reject) => {
- this.http.get('src/app/config/env.json')
- .map(res => res.json())
- .subscribe((env_data) => {
- this._env = env_data;
- this.http.get('src/app/config/' + env_data.configFileName + '.json')
- .map(res => res.json())
- .catch((error: any) => {
- console.error(error);
- return Observable.throw(error.json().error || 'Server error');
- })
- .subscribe((data) => {
- this._config = data;
- console.log('Loading is complete...', data);
- resolve(true);
- });
- });
- });
- }
- getEnv(key: any) {
- return this._env[key];
- }
- get(key: any) {
- console.log(this._config);
- return this._config[key];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement