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

35 lines
978 B
TypeScript
Raw Normal View History

2019-12-19 16:03:10 +00:00
import {Inject, Injectable} from '@angular/core';
2019-12-19 17:29:44 +00:00
import { Location,PathLocationStrategy,LocationStrategy } from '@angular/common';
2019-12-19 16:03:10 +00:00
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,private location:Location) {
this.httpClient = new HttpClient(xhrBackend);
this.config = null;
}
public getConfig(key: any) {
if (!this.config.hasOwnProperty(key)) {
console.error(`Config key ${key} not set`);
}
return this.config[key];
}
public load(): Promise<any> {
2023-03-06 13:04:14 +00:00
const url = this.location.prepareExternalUrl('/configuration.json');
2019-12-19 16:03:10 +00:00
return this.httpClient.get(url)
.toPromise()
.then(data => {
this.config = data;
//return data;
})
.catch(error => this.config = null);
2023-03-06 13:04:14 +00:00
}
2019-12-19 16:03:10 +00:00
}