RxJS5 finalize operator not called

后端 未结 3 1565
無奈伤痛
無奈伤痛 2021-02-07 09:20

I\'m trying to trigger a callback when all my observables are executed. In my other, older project i used finally like so and that worked like a charm:



        
3条回答
  •  离开以前
    2021-02-07 10:07

    If you want to do something when the observable completes then use the complete callback instead of finally/finalize:

    .subscribe(
        value => { console.log(`Next: ${value}`); },
        error => { console.log(`Error: ${error}`); },
        ()    => { console.log(`Completed`); }
    );
    

    Anyway finally/finalize should also work and will be called on error OR complete. Im pretty sure that your observable never completes. You can confirm this by using my code above.

    I see you are using Angular and subscribing to this.route.queryParams which never completes. You may create a new observable by use of first() so you get the value and it immediatly completes: this.route.queryParams.pipe(first())

提交回复
热议问题