I have been working on collecting data from an API in JSON format.
After implementing the code below, I was able to successfully gather the data inside Subscribe method.
However, when trying to manipulate this data outside of Subscribe within the .TS file itself, I faced some challenges.
I attempted using promises as well, but it seems like I did not implement them correctly, resulting in no positive outcome.
Do you have any suggestions on how I could effectively handle and process this data before displaying it on the screen?
getHour() {
this.hourService.getData()
.subscribe(
posts => this.posts = posts,
error => this.errorMessage = <any>error,
() => console.log(this.posts));
console.log(this.posts);
}
getData(): Observable<usersPerHour[]> {
return this.http.get(this.uri)
.map(this.extractData)
.catch(this.handleError);
}