Trying to call a webservice from Angular 2 that returns a single Json object:
{
"fullDisplayName": "test",
"result": "SUCCESS"
}
Below are the code snippets for my route:
Service
getJsonObject () {
return this.http.get(this.url)
.map(res => <jsonObject> res.json())
.do(jsonObject=> console.log(jsonObject))
.catch(this.handleError);
}
Component
getJsonObject() {
console.log('BEFORE')
this.service.getJsonObject()
.subscribe(
jsonObject=> this.jsonObject = jsonObject,
error => this.errorMessage = <any>error);
console.log(this.jsonObject)
console.log("AFTER")
}
All that I get is a undefined object but I can see the JSON in the console log in chrome. The funny thing is I place a log in the component before and after the call, both those logs are displayed before the JSON found is displayed in log, making it look like it's somehow trying to map the object before the web service returns the data.
Console Log
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
BEFORE
undefined
AFTER
Object {fullDisplayName: "test", result: "SUCCESS"}
Any help is greatly appreciated.