合并两个 observable 得到两个不同 Dto 的值

Merge two observables to get the value of two different Dto

我有两个observables,每个你得到一个Dto的值:

this.about.aboutHeInfo().subscribe((heInfo: HemDto) => {
        this.uiUtils.openDialogResizable({
          hem: heInfo
        }, true, AboutComponent).subscribe();
      });

this.about.aboutPeInfo().subscribe((peInfo: PeoDto) => {
        this.uiUtils.openDialogResizable({
          peo: peInfo
        }, true, AboutComponent).subscribe();
      });

问题是当创建两个 observable 时打开了两个屏幕,因为每个函数都创建了一个 apenDialog,我怎样才能合并两个 observable 并打开一个对话框?

这是我正在测试的合并:

const ob1 = this.about.aboutInfo().subscribe((heInfo: HemDto) => {
        this.heInfo= back;
      });

      const ob2 = this.about.aboutQoInfo().subscribe((peInfo: PeoDto) => {
          this.peInfo= people;
        });

forkJoin([ob1, ob2]).subscribe(() => {
        this.uiUtils.openDialogResizable({
          back: this.heInfo,
          people: this.peInfo
        }, true, AboutComponent).subscribe();
      });

你不应该在 merge 函数之前使用 subscribe,merge take observable not what subscribe returns

示例

const ob1 = this.about.aboutInfo()

const ob2 = this.about.aboutQoInfo()

forkJoin([ob1, ob2]).subscribe(([dto1, dto2]) => {
  ...
});