繁体   English   中英

“MyModel”类型缺少“Observable”类型的以下属性<mymodel> ': Angular 中的 _isScalar、source、operator、lift 等 6 个</mymodel>

[英]Type 'MyModel' is missing the following properties from type 'Observable<MyModel>': _isScalar, source, operator, lift, and 6 more in Angular

我有这个 TS model:

export interface ResearchContentByCompany {
    companyId: number;
    companyOverview: string;
    industryAnalysis: string;
    qualityAssessment: string;
    financials: string;
    valuations: string;
}

在服务中,这是我为获取数据而拨打的 api get call:

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.

我在执行此操作时在 get 调用中注意到。researchContentByCompany[0] = result 错误消失了,但随后数据丢失了,因为这不是一个数组,而只是一个具有属性的 object。

我该如何解决这个问题?

代替

researchContentByCompany: Observable<ResearchContentByCompany>;

定义如下,

researchContentByCompany: ResearchContentByCompany;

因为结果只是ResearchContentByCompany object 的类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM