import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Observable } from 'rxjs'; import { IConfigurationService } from './config.interface'; import { ConfigData } from './config.modal'; @Injectable() export class ConfigService implements IConfigurationService { private http: Http; private configIsLoaded: boolean; constructor (http: Http) { this.http = http; } private handleError (error: any) { let that: ConfigService = this; let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error'; this.configIsLoaded = false; console.error(errMsg); // log to console instead return Observable.throw(errMsg); } public retrieveConfigData(): Observable { return this.http.get('./config/config.json') .map((response: Response) => { let that: ConfigService = this; that.configIsLoaded = true; return response.json(); }) .catch(this.handleError); } public get isLoaded(): boolean { return this.configIsLoaded; } }