Fetching Data From Rest Web Service Using Angular 2 Http
I'm trying to fetch data from a REST web service using Angular 2 Http. I first inject the service in the constructor of the client component class that calls it: constructor (priva
Solution 1:
Since http requests are async, this.jsonData
won't be set at the time where you try to log it to console. Instead put that log into the subscribe callback:
getData(myArg: string){
this._myService.fetchData(myArg)
.subscribe(data => {
this.jsonData = JSON.stringify(data)
console.log(this.jsonData);
},
error => alert(error),
() => console.log("Finished")
);
}
Post a Comment for "Fetching Data From Rest Web Service Using Angular 2 Http"