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

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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