I am starting with angular 4 and server side rendering, currently I am trying to get a Proof of Concept fetching some data of one of my external API's. That API return a Json Object.
The site was rendering pretty well, however now that I included the call to fetch data it's not rendered and the response that I am getting doesn't seems to be what I should get.
In the app.components.ts I added:
private apiUrl= 'https://myapi/Users';
data: any = {};
constructor(private http: Http){
this.getUsers();
this.getData();
}
getData(){
let res=this.http.get(this.apiUrl).map((res: Response)=>res.json());
console.log("result:",res)
return res;
}
getUsers(){
this.getData().subscribe(data=>{
this.data=data;
})
}
Now, as you can see, in the getData method I am printing in console the result of the http calls, however I am getting this:
Observable {
_isScalar: false,
source: Observable { _isScalar: false, _subscribe: [Function] },
operator: MapOperator { project: [Function], thisArg: undefined } }
Why I am not getting there the json object? which could be the reason?
resis actually anObservable, not the data itself. Observables are asynchronous. To see the real data,console.logit at yoursubscribe(). call back function, or you can peek it inside yourmapcall back function.