I am a beginner in Angular and I have a JSON file that holds the configuration URL for my application.
Path: app/config/development.json
{
"apiUrl": "http://staging.domain.com:9000/",
"debugging": true
}
Below is the content of my config.service.ts file:
export class ConfigService {
private apiURL:any;
constructor (private http: Http) {}
getApiURL(){
this.http.get("app/config/development.json").map(res:Response=>res.json())
.subscribe(data=>{
this.apiURL = data;
})
console.log(this.apiURL);//this returns undefined
}
}
I am trying to ensure that this.apiURL
captures the response from the http.get
method. However, even when I create another method, the value of this.apiURL
remains unchanged from the getAPIURL()
method.
someMethod()
{
console.log(this.apiURL)//this must contain the response from http.get
}