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

366
Visualizações
CombineLatest, execute only once after all observables are complete

I'm trying to solve an issue. Currently, I'm opening a modal but I needed the combination of the 3 route observables for this. So, my code logic is something like this:

combineLatest([obs1, obs2, obs3])
    .subscribe(([s1, s2, s3]: any) => { 
        openModal();
    });

Since it will get executed 3 times, my modal will also be opened three times but I don't want it to do that but I know is expected behavior.

So, for this, the bad solution I implemented was using a flag like this:

let shouldOpen = true;

combineLatest([obs1, obs2, obs3])
    .subscribe(([s1, s2, s3]: any) => { 
        if(shouldOpen) {
            shouldOpen = false;
            openModal();
        }
    });

But of course, that's not a good solution.

So, the question is, Is there a way for me to keep using combineLatest but getting it executed only once?

Here's a Stackblitz if you want to try with combineLatest.

Note: I cannot use forkJoin or zip, I already tried those.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since you can't use forkJoin (which is the right answer), skip the first two emissions from the combineLatest

combineLatest([obs1, obs2, obs3])
  .pipe(skip(2))
  .subscribe(([s1, s2, s3]: any) => { 
    openModal();
  });

You could also use skipWhile to skip until all three are defined:

      .pipe(skipWhile(([s1, s2, s3]) => s1===undefined || s2 === undefined || s3===undefined))
over 4 years ago · Santiago Trujillo 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