Outside to the Observable?

In General, there is such code:

getLastVersionData(assemblyId: number) {
 return this.getLastVersion(assemblyId).subscribe(result => {
 var version = <Version>result;
 return this.getFileByVersion(version.id);
});
 }


I want the outside to subscribe and get the result returned by the function getFileByVersion, but can't do it, because it returns a Subscription.

What can I do to get my desired Observable?
March 19th 20 at 08:27
1 answer
March 19th 20 at 08:29
you should write
this.getLastVersion(assemblyId).flatMap(result => {
 var version = <Version>result;
 return this.getFileByVersion(version.id);
 }).subscribe(result=>{});
and what of the pipe with the map different? - Bryce.Terr commented on March 19th 20 at 08:32
@Bryce.Terr, pipe this is a new style, I have a year on angular not write, so I apologize, the pipe was introduced to tree shaking to do
but logic in General is that you need to build a chain and only in the end to sign up in the chain use different functions flatmap if you want to extract observable, switchmap if you need to cancel the previous (good for web requests), simply map return if unwrapped object - burdette_Paucek commented on March 19th 20 at 08:35

Find more questions by tags Reactive ExtensionsAngular