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

133
Vistas
concatMap is not subscribing for the second time

I am implementing concatMap operator. Even before doing that I tried making two subscriptions one after the other and it worked. The first subscription is made to the input field of form and the second subscription is made for the http request. Below is the code:

// AfterViewInit implementation
// this.form is a formGroup with formControl city

  ngAfterViewInit() {
    this.form.valueChanges.pipe(
      map (val=>val.city),
    ).subscribe(
      val => {this.request(val)}
    );
  }

   request(city){
    this.httpClient.get(url, {params:{
    ...
    }}).subscribe(
      value => {

      }, error => {}
    );
  }

The above snippet will make http call for each and every time the input field is updated. I modified the ngAfterViewInit as follows by adding concatMap:

  ngAfterViewInit() {
    this.form.valueChanges.pipe(
      concatMap(val=> this.request(val.city)),
    ).subscribe();
  }

Now, the requests are not made as expected. The request is made only once for the first time when the input is changed. The second request is never made for the updated input field. What am I doing wrong here?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

try fixing request function like this:

request(city){
    return this.httpClient.get(url, {params:{
    ...
    }}).pipe(tap(
      value => {

      }, error => {}
    ));
  }

with this fix there will be only one subscribe call in all the chain and operators will work as expected.

over 4 years ago · Santiago Trujillo 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