Question about managing Observables in Angular 14

Discussão em 'Angular' iniciado por Sergio Cea, Fevereiro 15, 2025.

  1. Sergio Cea

    Sergio Cea Guest

    I'm new to Angular and right now I'm using Angular 14 and I have a problem that happens to me often.

    For example, I have an array and I make a for loop to go through each of its indexes and I make a POST call. The call and the functionality of the call are in a service and there I manage the result.

    The problem I encounter is when below that for I have another http call that has to be executed when all the for calls have finished.

    How can I perform this task?

    for (let entrie of entries) {
    this.service.callPost(entrie);
    }

    // Only when all the for calls have finished
    this.service.callFinal();


    I have seen that one option is to use forkJoin and store each call in an observable array and execute the final function within the forkJoin.

    Thank you very much for the help.

    I want to perform this type of operation since I perform an update of several data (for calls) and when these finish based on whether one gave an error or not the final call updates in one way or another, but the problem is that being asynchronous the final call does not wait for the for calls to finish.

    Continue reading...

Compartilhe esta Página