TypeScript – wait for an observable/promise to finish, and return observable

The problem is that we convert observable into different type… with .subscribe – while we should not (it does not return observable) public makeRequest = (): Observable<any> => { return this.myObservable().subscribe( … // this is wrong, we cannot return .subscribe // because it consumes observable and returns ISusbcriber ); } When we have an observable… … Read more

Angular filter Observable array

it should be: getProjectByName(name: String) { return this.projects .map(projects => projects.filter(proj => proj.name === name)); } you misunderstood about filter operator. The operator using to filter data return from stream. Your stream return array of object, so you need filter array to get you needed value. The solution above will return an array after filtered, … Read more

RxJS Observables nested subscriptions?

As mentioned in comments, you are looking for the flatMap operator. You can find more details in previous answers : How to do the chain sequence in rxjs Why do we need to use flatMap? Your example would read as : this.returnsObservable1(…) .flatMap(success => this.returnsObservable2(…)) .flatMap(success => this.returnsObservable3(…)) .subscribe(success => {(…)});

“rxjs” observable.throw is not a function – Angular4

The error There are multiple modules with names that only differ in casing. is indicating the wrong import is being targeted with how you are trying to use Observable. The import should be with a capital “O” like: import { Observable } from ‘rxjs/Observable’; This will import the individual Observable operator, which be used in … Read more

Observable not assignable to type Observable

I think that your problem is located here: getRisks(): Observable<RiskListSummary[]> { return this.http.get(this.serviceUrl) .map(this.extractData()) <== passing result of function .catch(this.handleError()); <== passing result of function } You could use just passing function reference: getRisks(): Observable<RiskListSummary[]> { return this.http.get(this.serviceUrl) .map(this.extractData) .catch(this.handleError); } but this way you will lose this. Or you could use bind method to … Read more

When should I use `publishReplay` vs `shareReplay`?

shareReplay() is basically publishReplay().refCount() Definitely not. Both shareReplay and publishReplay (+ calling connect on it) will make the observable behind it hot. But the very important difference between them is: shareReplay: won’t stop emitting until it’s completed, no matter if there are no subscriptions anymore or not. publishReplay: will stop after the last subscriber unsubscribes … Read more

Angular 6 / Rxjs – how to basics: observables success, error, finally

I think there’s one key misunderstanding: You either have someone who wants “success and finally”, or “success and error” but none wants the 3 of them. This isn’t entirely true. Each Observable can send zero or more next notifications and one error or complete notification but never both. For example when making a successful HTTP … Read more