angular - “MyModel”类型缺少“Observable”类型的以下属性':Angular 中的 _isScalar、source、operator、lift 等 6 个
问题描述
我有这个 TS 模型:
export interface ResearchContentByCompany {
companyId: number;
companyOverview: string;
industryAnalysis: string;
qualityAssessment: string;
financials: string;
valuations: string;
}
在服务中,这是我为获取数据而进行的 api get 调用:
public getResearchSectionContentByCompany(companyId) {
return this.http.get<ResearchContentByCompany>("../api/contenteditor/getresearchcontentbycompany?companyId=" + companyId, {
headers: this.headers,
}).pipe(map(data => {
return data;
}));
}
在组件中我声明:
researchContentByCompany: Observable<ResearchContentByCompany>;
在 ngOnInit 方法中,我这样做:
this.contentEditorService.getResearchSectionContentByCompany(this.DataResult.companyId).subscribe(result => {
this.researchContentByCompany = result;
});
我能够按预期从 API 获取数据,但出现此错误:
Type 'ResearchContentByCompany' is missing the following properties from type
'Observable<ResearchContentByCompany>': _isScalar, source, operator, lift, and 6 more.
当我执行 this.researchContentByCompany[0] = result 时,我在 get 调用中注意到错误消失了,但是数据丢失了,因为这不是一个数组,而只是一个具有属性的对象。
我该如何解决这个问题?
解决方案
代替
researchContentByCompany: Observable<ResearchContentByCompany>;
定义如下,
researchContentByCompany: ResearchContentByCompany;
因为结果只是ResearchContentByCompany
对象的类型。
推荐阅读
- c# - 使用 MemoryStream 和 WebApi 返回图像
- serverless-framework - 如何在 Bash 中捕获无服务器部署的 URL?
- c++11 - 从它使用的 DLL 中获取进程的堆栈跟踪
- kibana - 查询包含 //admin$ 的文件夹路径
- excel - 使用 vba 将工作表复制到其他工作簿
- postgresql - 使用 postgresql 在单个查询中从两个不同的表中删除
- arrays - 在 mongodb 中使用条件从集合中检索子文档
- java - Netbeans 不再自动更新我的 Grails 运行应用程序
- c# - 单元测试 Linq XML 函数
- html - 基于父母大小的相同高度兄弟姐妹