How can I avoid multiple nested subscriptions using RxJS operators?

前端 未结 4 1582

I am working on a file encryption and upload class using Angular. Many of these operations are async and therefore the methods I wrote are returning RxJS Observables.

<
4条回答
  •  时光说笑
    2020-12-11 04:32

    You can merge those observables using mergeMap rxjs operator and get rid of nested subscriptions.

    Though there is one catch, Be aware that because mergeMap maintains multiple active inner subscriptions at once it's possible to create a memory leak through long-lived inner subscriptions.

    For reference and example: https://www.learnrxjs.io/operators/transformation/mergemap.html

提交回复
热议问题