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

252
Visualizações
Rxjs subject switch map to call another observable

I am trying to call another observable on every emitted value in the subject.

My problem now is the first emitted value to the subject triggers the switchMap and calls the confirmCsvUpload(...), but every next emitted value does trigger the switchMap but not the confirmCsvUpload(...).

Can someone figure out why its not calling the function?

// Subject
private _confirmCsvUpload = new Subject<{ account: Account, previewData: PreviewData[], previewId: string }>();

// Subscription to the Subject 
this._confirmCsvUpload.pipe(
  switchMap(previewData => this._uploadCsvService.confirmCsvUpload(previewData.account, previewData.previewData, previewData.previewId))
).subscribe();

// Function which emits value to the subject (Not the function who gets called in the switchMap())
confirmCsvUpload(): void {
  this._confirmCsvUpload.next({ account: this.account, previewData: this._previewData, previewId: this.getPreviewIdFromRoute() });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i try to replay you scenary with:

  private _confirm$ = new Subject();
  private _destroy$ = new Subject();
  ngOnInit() {
    this._confirm$
      .pipe(
        takeUntil(this._destroy$),
        tap((v) => console.log('[SUB]', v)),
        switchMap((v: any) => this.secondCall())
      )
      .subscribe();
  }

  secondCall() {
    console.log('[SECOND CALL]');
    return of();
  }

  callSub() {
    console.log('[NEXT VALUE]');
    this._confirm$.next('value');
  }

  ngOnDestroy() {
    this._destroy$.next(null);
    this._destroy$.complete();
    console.log('[NG ON DESTROY]');
  }

Console log with 2 call:

[NEXT VALUE]
[SUB] value
[SECOND CALL]

-- second time:

[NEXT VALUE]
[SUB] value
[SECOND CALL]
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