Does Subject.complete() unsubscribe all listeners?

If you want to be sure it removes all Observers you can check it for yourself in https://github.com/ReactiveX/rxjs/blob/master/src/internal/Subject.ts#L91. It calls complete() on all Observers (Observers are typically just dumb objects implementing Observer interface) and then sets this.observers.length = 0;. So the answer is yes. Your approach is valid, it’s basically the same as Angular2 regularly … Read more

RxJava introduced Single. How do I convert an Observable to a Single?

I think another answer is outdated. You should probably check the following methods. singleOrError: Emits the one and only element, IndexOutOfBoundsException if the source is longer than 1 item or a NoSuchElementException if the source is empty. firstOrError: Emits the first element or a NoSuchElementException if the source is empty. lastOrError: Emits the lastelement or … Read more

Angular – Observable with async pipe used multiple times in template… Good Practice or Bad?

Using the async pipe makes handling subscriptions much easier. It automatically handles unsubscribing unlike subscribing in the component. That said, there is a better pattern than what the example is showing. Rather than having multiple async calls on components, you can write it 2 different ways. I’m assuming these components are in the same template … Read more

How to use the MatTableDataSource with an observable?

You should be able to new up the MatTableDataSource once at the class level and then use the data setter in ngOnInit. dataSource = new MatTableDataSource<Thing>(); @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatSort, { static: true }) sort: MatSort; ngOnInit() { getThings().subscribe(things => { this.dataSource.data = things; this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; }); … Read more

Type ‘Observable’ is not assignable to type ‘Observable’

There are two ways to do this, and it depends on which version of RxJS / Angular that you are using. Here are the two ways to do it depending on your versions: // Using RxJS v4 / Angular v2-4. I assume that you’re using the HttpModule… import ‘rxjs/add/operator/map’; public getUsers(url: string): Observable<IUser[]> { return … Read more

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

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 => {(…)});