Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Ejecutar métodos uno por uno en Angular y RxJS
this.userClient.getUser(userName) .pipe( concatMap( user => { this.user = user; return this.userClient.setStatus(this.user.id, 'banned'); } ), concatMap( user => { //set property... return this.userClient.deleteImg(user.img); } ), mergeMap( user => { this.user = user; return this.userClient.setGroup(user.id, 'test'); } ) ) .subscribe( user => { //actions }, error => ... )

Me gustaría que mis métodos se activen uno por uno, no todos a la vez. ¿Cómo puedo hacer esto? forkJoin es la única salida?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Mantenga el primer switchMap, pero luego devuelva un concat. El concat secuenciará los tres elementos que desea. Concat espera hasta que uno termine, luego hace el siguiente, y así sucesivamente.

Puede encontrar más información sobre concat en los documentos de RxjS Concat

 this.userClient.getUser(userName) .pipe( switchMap( user => { this.user = user; return concat( this.userClient.setStatus(this.user.id, 'banned'), this.userClient.deleteImg(user.img), this.userClient.setGroup(user.id, 'test') ); } ) ) .subscribe( ([user]) => { //actions }, error => ... )

En un episodio de Angular Show , describieron algunos de estos operadores de mapeo de orden superior . Puede ayudar a comprender cómo funcionan.

over 4 years ago · Santiago Trujillo Report

0

Solo usa switchMap

 this.userClient.getUser(userName) .pipe( switchMap( user => { this.user = user; return this.userClient.setStatus(this.user.id, 'banned'); } ), switchMap( user => { //set property... return this.userClient.deleteImg(user.img); } ), switchMap( user => { this.user = user; return this.userClient.setGroup(user.id, 'test'); } ) ) .subscribe( user => { //actions }, error => ... )
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!