如何在switchOperator中调用forkJoin?

How to call forkJoin in switchOperator?

我尝试在 switchMap 中调用 forkJoin:

this.route.params.pipe(
  pluck('cadnum'),
  tap((cadnum) => {
    this.r1.repositoryModel.findallversionbycadnum.model.cadnum = cadnum;
    this.r2.repositoryModel.findallversionbycadnum.model.cadnum = cadnum;
    this.r3.repositoryModel.findallversionbycadnum.model.cadnum = cadnum;
  }),
  switchMap(() => forkJoin(
    egrn.parcels.versions.load(),
    egrn.premisses.versions.load(),
    egrn.rights.versions.load()).pipe(
      tap(([res1, res2, res3]) => {
        egrn.parcels.versions.set(res1);
        egrn.premisses.versions.set(res2);
        egrn.rights.versions.set(res3);
      }),
      catchError((error) => of(error)),
    ),
  ),
)).subscribe((response) => {
  console.log(response);
});

但是不行,如何在switchMap里面调用forkJoin

要 forkJoin 发出结果,所有 egrn.parcels.versions.load(), egrn.premisses.versions.load(), egrn.rights.versions.load() 必须完整。

您可以尝试将 forkJoin 切换为 combineLatest 或在第一次发射后使用 take(1) 完成流,例如:egrn.parcels.versions.load().pipe(take(1))