This is how i am working now:
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 want to prevent this kind of function with id1, url1, id2, url2, id3, url3...
I am trying to write a function that should take as params an Array of IDs and an Array of URLs. With Observable.forkJoin
the for loop should execute each request getById to Backend-URL that are in Array.
My problem is by the for loop
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());
}
)
}
How can I do that?