Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
RxJS - Combine multiple observables and emit any value

I know how to combine observables and fetch the result when all observables emit at least one value (combineLatest, forkJoin, etc.).

But how can I emit a value when one of many observables emits a value?

For example:

const adModelChangedObs$ = this.editAdService.adModelChanged; // Angular subject one
const refreshPreviewClickedObs$ = this.editAdService.refreshPreviewClick // Angular subject two

merge([adModelChangedObs$, refrshPreviewClickedObs$]).subscribe(() => {
     console.log('One of the two observables emitted a value');
});

The subscribe handler is not being executed, although I tried it with many RxJS operators for far.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As mentioned in the comments, the merge function should help in your case, however, you have to pass the observables as args, not as an array.

You can try it like the following:

// import { merge } from 'rxjs';

const adModelChangedObs$ = this.editAdService.adModelChanged; // Angular subject one
const refreshPreviewClickedObs$ = this.editAdService.refreshPreviewClick; // Angular subject two

merge(adModelChangedObs$, refrshPreviewClickedObs$).subscribe(() => {
  console.log('One of the two observables emitted a value');
});

However, if that's not working, then you need to make sure that your editAdService observables emit the value correctly.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda