Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Spring and Angular: How to make two http calls one after another with a condition

I have an Angular interface which handles a file upload, after a submit button it persist this file in MySQL database. I want to make another call inside this submit method but the second http call needs the id of that entity persisted(file) and I don't know how to retrieve that specific id from that file uploaded.

this is my submit method:

onSubmit() {

        const statementFile = new StatementFile();

// *******
// here are some business logic
// *******


// this will send POST request and save it to MySQL.
        this.statementFileService.postStatementFile(statementFile).subscribe(
            {
                next : (response) => {
                    alert('You have been submitted your statement file, check MySQL');
                },
                error: (err) => {
                    alert(`there was a problem: ${err.message}` );
                }
            }
        );


// this is the second http request I want to call but it needs particularly the id of that statementFile uploaded.
this.activitiWorkflowService.createPreccess(statementFile.statementFileId).pipe(takeUntil(this._unsubscribeAll), debounceTime(3000)).subscribe(
            (data: any) => data
        );

    }

this is my StatementFile class:

export class StatementFile{

    statementFileId: number;
    dateReception: Date;
    label: string;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use switchMap operator to chaining requests. statementFile.statementFileId or response.statementFileId or something else from postStatementFile request you will use to call next request.

 this.statementFileService.postStatementFile(statementFile)
      .pipe(
        switchMap(response => this.activitiWorkflowService.createPreccess(statementFile.statementFileId).pipe(takeUntil(this._unsubscribeAll)))
      )
      .subscribe({
          next : (data: any) => data,
          error: (err) => {
             alert(`there was a problem: ${err.message}` );
          }
        }
      );
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda