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

187
Views
Quiero mostrar datos relacionados juntos de diferentes API

Tengo dos API:

componente.ts

 ngOnInit(): void { this.getQueryCountriesList().subscribe(arg => { this.countryDatas = arg; }); this.getQueryNights().subscribe(obj => { this.nightDatas = obj; }); ........ ...... getQueryCountriesList(){ return this.http.get<any>(this.APIUrl + "/Visitor?tourType="+ this.tourType +"&year=" + this.selectedYear + "&month=" + this.selectedMonth +"&gender=" + this.selectedGender + "&age="+this.selectedAge); } getQueryNights(){ return this.http.get<any>(this.APIUrl + "/Nights?tourType="+ this.tourType +"&year=" + this.selectedYear + "&month=" + this.selectedMonth +"&gender=" + this.selectedGender + "&age="+this.selectedAge); }

cada dato tiene la misma identificación, quiero mostrar visitas (de la primera API) y noches (segunda API) una al lado de la otra en la tabla: componente.html

 <tr *ngFor="let country of countryDatas; let nights; of: nightDatas"> <th [id]="country.countryId + '1'">{{ country.countryNameGe }}</th> <td [id]="country.countryId + '2'">{{ country.value }}</td> <td [id]="country.countryId + '3'">{{ nights.value }}</td> </tr>

con el siguiente código obtengo solo noches o solo visitas en cada columna al azar

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Intente usar Promise.all() para esperar a que las dos api devuelvan la respuesta, puede ser útil.

about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar el poder de rxJS. En este caso, puede usar forkJoin .

 import { forkJoin } from 'rxjs'; ngOnInit(): void { forkJoin({ countries: this.getQueryCountriesList(), nights: this.getQueryNights() }).subscribe(({countries, nights}) => { this.countryDatas = countries; this.nightDatas = nights; });

Entonces, ¿qué está pasando aquí? Con forkJoin , está esperando que se emitan ambos observables de su API, luego emita un objeto que contenga sus datos.

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el operador rxjs combineLatest que esperará a que ambos observables emitan al menos un valor. Y a partir de ahí, construya su matriz que contenga ambos valores:

 import { combineLatest } from 'rxjs'; ngOnInit(): void { queryCountriesList$ = this.getQueryCountriesList(); queryNights$ = this.getQueryNights(); combineLatest([queryCountriesList$,queryNights$]) .subscribe(([queryCountriesList, queryNights]) => { // create your object here } }
about 4 years ago · Juan Pablo Isaza 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!