I want to load all url from a config file. I've created json file named 'config.json", ConfigurationService.ts to get the URL by key. But I cannot get the URL by key.
config.json:
{
"loginUrl": "http:example/login",
"verifyUrl": "http:example/verify"
}
ConfigurationService.ts:
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Headers, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class ConfigurationService {
constructor(private http:Http) {}
private result: Object;
getConfiguration(key) {
return this.http.get('./app/config/config.json').map(res => {
res.json();
this.result = res._body;
return this.result[key]; //returns 'undefined', but when I return only 'this.result' it shows me all json data {...}
});
}
}
part of auth_service.ts:
private x =this.configurationService.getConfiguration("verifyUrl").subscribe((result) => console.log(result));
How do I receive only the loginUrl for example?