My current approach:
getTwoObjectById(url1: string, id1: string, url2: string, id2): any{
return Observable.forkJoin(
this.http.get(url1 + `/${id1}`, this.jsonWebToken()).map(res =>
res.json()),
this.http.get(url2 + `/${id2}`, this.jsonWebToken()).map(res =>
res.json())
);
}
I am looking for a way to generalize the function above to handle multiple IDs and URLs dynamically.
I am attempting to create a new function that accepts arrays of IDs and URLs as parameters. Using Observable.forkJoin
, a loop will execute requests for each ID using the corresponding URL from the arrays.
getObjectsById(ids: Array<string>, urls: Array<string>): Observable<any>{
return Observable.forkJoin(
for(let i = 0; i++; i<ids.length) {
this.http.get(urls[i] + `/${ids[i]}`, this.jsonWebToken()).map(res => res.json());
}
)
}
I am facing challenges with implementing the loop functionality in the newly proposed function.