Skip to content
Advertisement

Angular-Listening to store changes & emit a value from a Service component to a different component – only after Service completes certain operations

Here we have to classes GetDataAsyncService which waits for change in the store (and not executes the block of code under it until a change in the store ( this.getDataAsyncService.getAsyncData().subscribe((data)=>{ )}). When it is called from MainComponent it will get return of(propA); (from GetDataAsyncService) before the block of code in the listener is executed – because the listener is still waiting for a change in the store. I want to emit that observable only when that operation block is executed.

JavaScript

Advertisement

Answer

You can achieve that by returning the Observable itself from the getData function and mapping it to the required prop, instead of subscribe to it, like the following:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement