35 lines
954 B
TypeScript
35 lines
954 B
TypeScript
import { Location } from '@angular/common';
|
|
import { HttpClient, HttpXhrBackend } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
|
|
@Injectable()
|
|
export class AppConfig {
|
|
|
|
private config: object = null;
|
|
private httpClient: HttpClient;
|
|
|
|
constructor(xhrBackend: HttpXhrBackend,private location:Location) {
|
|
this.httpClient = new HttpClient(xhrBackend);
|
|
this.config = null;
|
|
}
|
|
|
|
public getConfig(key: any) {
|
|
// eslint-disable-next-line no-prototype-builtins
|
|
if (!this.config.hasOwnProperty(key)) {
|
|
console.error(`Config key ${key} not set`);
|
|
}
|
|
return this.config[key];
|
|
}
|
|
|
|
public load(): Promise<any> {
|
|
const url = this.location.prepareExternalUrl('/configuration.json');
|
|
return this.httpClient.get(url)
|
|
.toPromise()
|
|
.then(data => {
|
|
this.config = data;
|
|
//return data;
|
|
})
|
|
.catch(() => this.config = null);
|
|
}
|
|
}
|