this.subscription1$
.pipe(
takeUntil(this.ngUnsubscribe),
map((data1) => {
return data1.map((data2, index) => {
// we should return here the value, not the subscription
return this.subscription2(index + 1).pipe(
takeUntil(this.ngUnsubscribe),
map((data3) => {
return of(data3);
})
);
});
}),
)
.subscribe((data) => {
console.log('FINAL: ', data);
});
That final console shows:
[Observable, Observable, Observable, Observable]
how could I get the other subscription data directly without getting any observable?
Depens how you want to combine subscription2 results. If you want to wait for all to complete you may use forkJoin
this.subscription1$.pipe(
takeUntil(this.ngUnsubscribe),
switchMap((data1) => {
return forkJoin(...data1.map((data2, index) => this.subscription2(index + 1)))
})
).subscribe((data) => {
console.log('FINAL: ', data);
})
Maybe you want combineLatest to watch for particular changes. Choose proper operator here according your usecase