(Angular应用)
我在循环访问其页面时从https://jobs.github.com/positions获取数据, 因为每个页面包含50个可用职位,所以我想从他们所有页面中获取职位。
Service.ts:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class PositionserviceService {
// uri = 'https://jobs.github.com/positions'
constructor(public http: HttpClient) { }
getAllPositions(){
return this.http.get('https://cors-anywhere.herokuapp.com/https://jobs.github.com/positions.json');
}
getAllPoistions2(page){
return this.http.get(`https://cors-anywhere.herokuapp.com/https://jobs.github.com/positions.json?page=${page}`);
}
}
Component.ts:
getAllPositions(){
for(let i = 1; i<=5; i++){
this.positions.push(this.positionService.getAllPoistions2(i))
}
console.log("This positions:",this.positions)
forkJoin(this.positions).subscribe((data:Object[]) => {
this.allPositions = data
console.log("All Positions:", this.allPositions)
})
}
回复为:
所以我的问题是:如何将这5个数组合并为一个数组?
非常感谢!