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

294
Vistas
Why Rxjs combineLatest depends on both subscription and not call when one of them changed?

I have two subscriptions item as you see in the image: enter image description here

one of them is search input another one is a selection filter. I want to change the result when one or both of them change. I use Rxjs combineLatest so when both of them or search input change, everything is ok, but when changing the Partner type at the first, the response does not change.

ngOnInit() {
super.ngOnInit();
this.getAllPartners();

combineLatest([this.searchPartnerFc.valueChanges, this.filterFc.valueChanges])
  .pipe(
    switchMap(([search, filter]) => {
      let partnersBySearch = this.getSearchResult(search);
      let partnersByFilter = this.getFilterResult(filter);

      this.partners = partnersBySearch.filter(item => partnersByFilter.indexOf(item) > 0);
      return this.partners;
    }),
  )
  .subscribe();
}

getFilterResult(filterKey: string) {
    if (filterKey == 'All') return this.allPartners;
    else return this.allPartners.filter(partner => partner.partnerType == filterKey);
}

getSearchResult(searchString: string) {
    return this.allPartners.filter(x => x.partnerName.toLowerCase().includes(searchString));
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can achieve your desired result by providing a default emission for each of your source observables using startWith:

combineLatest([
  this.searchPartnerFc.valueChanges.pipe(startWith('')), 
  this.filterFc.valueChanges.pipe(startWith('All'))
]).pipe(
  ...
);
about 4 years ago · Juan Pablo Isaza Denunciar

0

I think it's not working because of the nature of the combineLatest operator. It will only emit when both of the observables have emitted an initial value first. So when only the first observable emits, and the second doesn't, it will not do anything: https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

I think you need a merge operator here: https://www.learnrxjs.io/learn-rxjs/operators/combination/merge

Also please take a look here on this thread: How to 'wait' for two observables in RxJS

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