From 677608c14de1611853e054c8b3b17e42c79405a2 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Thu, 19 Dec 2019 17:03:10 +0100 Subject: [PATCH] Fix configuration loading --- projects/common/src/fm/shared/app.config.ts | 68 +++++++++++---------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/projects/common/src/fm/shared/app.config.ts b/projects/common/src/fm/shared/app.config.ts index 8a8104a..a36c385 100644 --- a/projects/common/src/fm/shared/app.config.ts +++ b/projects/common/src/fm/shared/app.config.ts @@ -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 { - 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 { + 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); + }; +}