首页 > 解决方案 > 使用 forkJoin Angular 6 链接

问题描述

表单处于添加或编辑模式。

动作1:在添加模式下我不需要拉项目数据,而在编辑模式下,我需要拉项目数据。这是有条件的步骤。

动作 2:在添加/编辑模式下我都有一个下拉菜单,我需要从数据库中提取选项。

我有以下 forkJoin

forkJoin(

  this.groupService.getGroupListById(zGroupTypes.ProjectSubType).pipe(
    map(res => res),
    catchError(e => throwError(e)) //of(this.errorMessageService.getErrorMessage(e))
  ),

  this.formMode === zFormMode.Add ? of(this.subProjectInfo = <SubProject>{}) : this.projectSubService.getSubProjectInfoById(this.subId).pipe(
    map(res => res),
    catchError(e => throwError(e)) //of(this.errorMessageService.getErrorMessage(e))
  )
)
  .subscribe(
    res => {
      console.log(res);
      //this.groupInfo = res[0];
      //this.subProjectInfo = res[1];
    },
    error => {
      console.log(this.errorMessageService.getErrorMessage(error));
    }
  );

问题:

两者this.groupInfo = res[0];this.subProjectInfo = res[1];导致

(TS) type '{}' is not assignable to type 'Group[]'.
Property 'length' is missing in type '{}'.

(TS) type '{}' is not assignable to type 'SubProject'.
Property 'length' is missing in type '{}'.

订阅中res is [{},{}]

控制台日志

在此处输入图像描述

如何在这里进行?

更新1:

这工作,没有更多的错误

this.groupInfo = <Group[]>res[0];
this.subProjectInfo = <SubProject>res[1];

我有适当的解决方案吗?forkJoin 在组件内部。

标签: observableangular6

解决方案


推荐阅读