类型 'MyModel' 缺少类型 'Observable<MyModel>' 中的以下属性:_isScalar、source、operator、lift,以及 Angular 中的其他 6 个属性
Type 'MyModel' is missing the following properties from type 'Observable<MyModel>': _isScalar, source, operator, lift, and 6 more in Angular
我有这个 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] = 结果时注意到在 get 调用中,错误消失了,但随后数据丢失了,因为这不是一个数组,而只是一个具有属性的对象。
我该如何解决这个问题?
而不是
researchContentByCompany: Observable<ResearchContentByCompany>;
定义如下,
researchContentByCompany: ResearchContentByCompany;
因为结果只是 ResearchContentByCompany
对象的类型。
我有这个 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] = 结果时注意到在 get 调用中,错误消失了,但随后数据丢失了,因为这不是一个数组,而只是一个具有属性的对象。
我该如何解决这个问题?
而不是
researchContentByCompany: Observable<ResearchContentByCompany>;
定义如下,
researchContentByCompany: ResearchContentByCompany;
因为结果只是 ResearchContentByCompany
对象的类型。