Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2.  
  3. import { Observable } from 'rxjs/Observable';
  4. import 'rxjs/add/operator/catch';
  5. import 'rxjs/add/operator/map';
  6.  
  7. import { Http } from '@angular/http';
  8.  
  9.  
  10. @Injectable()
  11. export class Config {
  12.  
  13. private _config: Object;
  14. private _env: Object;
  15.  
  16. constructor(private http: Http) {}
  17.  
  18. load() {
  19. console.log('Load configuration...');
  20. return new Promise((resolve, reject) => {
  21. this.http.get('src/app/config/env.json')
  22. .map(res => res.json())
  23. .subscribe((env_data) => {
  24. this._env = env_data;
  25. this.http.get('src/app/config/' + env_data.configFileName + '.json')
  26. .map(res => res.json())
  27. .catch((error: any) => {
  28. console.error(error);
  29. return Observable.throw(error.json().error || 'Server error');
  30. })
  31. .subscribe((data) => {
  32. this._config = data;
  33. console.log('Loading is complete...', data);
  34. resolve(true);
  35. });
  36. });
  37. });
  38. }
  39.  
  40. getEnv(key: any) {
  41. return this._env[key];
  42. }
  43.  
  44. get(key: any) {
  45. console.log(this._config);
  46. return this._config[key];
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement