I want to make an API call in a loop with an array of IDs and store the response of each API call into a variable as an array.
const myIds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 19]
forkJoin(
myIds.map((i: number) =>
this.http.get('apicallwith/${i}')
.subscribe(res) => {
const allResponses = [...res];
console.log(allResponses) // always getting the response of my first ID
}
)
)
I tried forkJoin from what I understood and not sure where I'm doing wrong
forkJoin(myIds.map((i:number)=>this.http.get('apicallwidth/'+i))).subscribe((res:any[])=>{console.log(res)}). In two steps:obs$=forkJoin(myIds.map((i:number)=>this.http.get('apicallwidth/'+i)));obs$.subscribe(...)