observable - 使用 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 在组件内部。
解决方案
推荐阅读
- python - 对列中的值进行切片以为另一列创建条件
- android - Android 开发部署到 Google 控制台失败
- swift - 使用 Core Data 从 Cloud Firestore 中提取数据后保存空数据模型
- java - 根据用户输入中出现的字符从包含字母的数组列表中删除字符
- python - 如何在 python 中的稀疏矩阵上应用 colamd 算法?
- react-native - React useEffect 引发“创建不是函数”错误
- java - 在 Optional 中包装数据类型导致的 ClassCastException
- kubernetes - Kubernetes:将本地文件夹挂载到 pod 时出现问题 - “0/1 个节点可用:1 个节点发生卷节点关联性冲突。”
- mongodb - 如何在一个聚合管道阶段进行计数并在稍后阶段使用它?
- asp.net - 如何从 Web API 获取数据到 Xamarin 表单选择器?