How to unsubscribe from an Observable returned by forkJoin?

前端 未结 2 1664
抹茶落季
抹茶落季 2021-02-19 06:58

In my Angular2-typescript app, I\'m using forkJoin to return an Observable only once all the parallel HTTP calls were made.

Issue: the subscription call

2条回答
  •  隐瞒了意图╮
    2021-02-19 07:29

    You can cancel it. Let's say observables is an array of http requests you prepared to trigger (executed via httpClient).

    this.forkJoinSubscription = forkJoin(observables).subscribe(responses => {
        . . . do something
    });
    
    this.forkJoinSubscription.unsubscribe();
    

    You may notice in your network tab that those requests were cancelled.

提交回复
热议问题