forkJoin在Angular 6中不使用URL和POST对象的动态数组

forkJoin在Angular 6中不使用URL和POST对象的动态数组,angular,rxjs,fork-join,Angular,Rxjs,Fork Join,这是我的技术堆栈 角度-6.1.2 打字脚本-2.7.2 rxjs-6.2.2 下面是Angular中forkJoin方法的代码。正在后端调用Post请求。但是参数没有通过 import { Observable } from 'rxjs'; import 'rxjs/add/observable/forkJoin'; reqArray = []; for (let i = 0; i < this.array.length; i++) {

这是我的技术堆栈

角度-6.1.2

打字脚本-2.7.2

rxjs-6.2.2

下面是Angular中forkJoin方法的代码。正在后端调用Post请求。但是参数没有通过

  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)
    );
当我以静态方式在没有for循环的情况下传递数据时,它工作得很好

    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);

        });
但是,在我的例子中,我必须根据一些条件创建URL数组,所以静态添加它是不可能的


我应该在代码中更改什么?

您需要分散阵列

forkJoin(...this.reqArray)

我有一个非常类似的场景,但蔓延导致了皮棉问题
forkJoin
也支持一组可观察对象,因此问题将出现在其他地方:
forkJoin(...this.reqArray)