@leonardofmed wrote:
I have a function that get some data from DB, store in localStorage and then do something with it. To get the data I’m using the Angular’s HttpClient, which uses Observables in its methods. The problem I’m facing is that when
processData()is fired, thelocalStoragewas not populated yet.Here is how I’m doing the coding so far:
mainFunction(): Promise<void> { return this.getData().then(() => { return this.processData().then(() => { //... }) }) } // Get data from DB and then store in localStorage getData(): Promise<Subscription> { // Declare some data to send //... return this.http.post(myLink, myArray, httpOptions) .subscribe(res => { // Store retrieved data in localStorage return this.storeData(res); }); }I can’t just get the data from
getData()and pass toprocessData, for some other reasons I need to update the localStorage before proceed. I believe this situation is happening because I’m returning a Subscription toprocessData()and not the updatedlocalStoragedata, which is my objective. I tried to do this in some ways, as stated here usingmap(), but this generate some other errors. Is there other method that I can use to acomplish what I want?
Posts: 3
Participants: 2