FarmMapsLib/projects/common/src/fm/shared/app.config.ts

33 lines
782 B
TypeScript
Raw Normal View History

2019-07-15 14:54:19 +00:00
import {Inject, Injectable} from '@angular/core';
import {HttpClient, HttpXhrBackend} from '@angular/common/http';
import {Observable} from 'rxjs';
@Injectable()
export class AppConfig {
private config: Object = null;
private httpClient: HttpClient;
constructor(xhrBackend: HttpXhrBackend) {
this.httpClient = new HttpClient(xhrBackend);
this.config = null;
}
public getConfig(key: any) {
if (!this.config.hasOwnProperty(key)) {
2019-11-06 08:08:42 +00:00
console.error(`Config key ${key} not set`);
2019-07-15 14:54:19 +00:00
}
return this.config[key];
}
public load(): Promise<any> {
return this.httpClient.get('/configuration.json')
.toPromise()
.then(data => {
this.config = data;
//return data;
})
.catch(error => this.config = null);
};
}