Fix configuration loading
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
parent
fd8025c674
commit
677608c14d
@ -1,33 +1,35 @@
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
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> {
|
||||
return this.httpClient.get(this.location.prepareExternalUrl('/configuration.json'))
|
||||
.toPromise()
|
||||
.then(data => {
|
||||
this.config = data;
|
||||
//return data;
|
||||
})
|
||||
.catch(error => this.config = null);
|
||||
};
|
||||
}
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import { Location,PathLocationStrategy } from '@angular/common';
|
||||
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> {
|
||||
var url = this.location.prepareExternalUrl('/configuration.json');
|
||||
if(url.startsWith("#")) url='/configuration.json';
|
||||
return this.httpClient.get(url)
|
||||
.toPromise()
|
||||
.then(data => {
|
||||
this.config = data;
|
||||
//return data;
|
||||
})
|
||||
.catch(error => this.config = null);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user