Here is my tech stack
Angular - 6.1.2
TypeScript - 2.7.2
rxjs - 6.2.2
Here is the code for my forkJoin method in Angular. Post requests are being called at the backend. But the params are not being passed.
import { Observable } from 'rxjs';
import 'rxjs/add/observable/forkJoin';
reqArray = [];
for (let i = 0; i < this.array.length; i++) {
if(array[i]==true)
{
let obj = { name: 'Test', status: array[i] };
this.reqArray.push(this.http.post(url, { params: obj }).pipe(map((res: Response) => res)));
}
}
forkJoin(this.reqArray).subscribe(
data => {
console.log(data);
},
err => console.error(err)
);
Tried this approach as well, but I get same response.
Observable.forkJoin(this.reqArray).subscribe(
data => {
console.log(data);
},
err => console.error(err)
);
When I pass data without the for loop in a static way, it works fine.
forkJoin(
this.http.get(url, { params: obj }).pipe(map((res: Response) => res)),
this.http.get(url, { params: obj2 }).pipe(map((res: Response) => res)),
this.http.get(url, { params: obj3 }).pipe(map((res: Response) => res)),
this.http.get(url, { params: obj4 }).pipe(map((res: Response) => res))
).subscribe(
data => {
console.log(data);
});
But, in my case I would have to create URLs array based on a few conditions, so adding it statically won't be possible.
What should I change in my code?