-1
I am collecting data provided by a JSON API.
With the code below I can see that the data was collected within the Subscribe.
But outside it, inside the file itself . TS I cannot manipulate this data.
I tried to use the Promise, but I don’t think I used it correctly, because I didn’t get a positive result either.
How I could handle this data before presenting on screen?
getHour() {
this.hourService.getData()
.subscribe(
posts => this.posts = posts,
error => this.errorMessage = <any>error,
() => console.log(this.posts));
console.log(this.posts);
}
You can put the return of this console.log?
– Maycon F. Castro
Yes, I’ve already added
– Osmar Ferreira
Opa they are only available within the same subscribe. That pq the http and asynchronous call.
– Eduardo Vargas
I understood, and for me to use this data outside of subscribe I would need to use an async or await?
– Osmar Ferreira
Rxjs and observables and other different form of async await to deal with asynchronizity.
– Eduardo Vargas
but if it is inside the subscribe, why not change the data, since it was received correctly? or Oce uses the suggestion of @Eduardovargas
– fsi
@Fsi Eduardo explained further below. I was already finding what he said tbm.
– Osmar Ferreira