简体   繁体   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

I have this TS model:我有这个 TS model:

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

In the service, this is the api get call I'm making to get the data:在服务中,这是我为获取数据而拨打的 api get call:

public getResearchSectionContentByCompany(companyId) {
        return this.http.get<ResearchContentByCompany>("../api/contenteditor/getresearchcontentbycompany?companyId=" + companyId, {
            headers: this.headers,
        }).pipe(map(data => {
            return data;
        }));
    }

In the component I declare this:在组件中我声明:

 researchContentByCompany: Observable<ResearchContentByCompany>;

And in ngOnInit method I do this:在 ngOnInit 方法中,我这样做:

this.contentEditorService.getResearchSectionContentByCompany(this.DataResult.companyId).subscribe(result => {
                                this.researchContentByCompany = result;
                            });

I'm able to get the data as expected from the API but I'm getting this error:我能够按预期从 API 获取数据,但出现此错误:

    Type 'ResearchContentByCompany' is missing the following properties from type 
'Observable<ResearchContentByCompany>': _isScalar, source, operator, lift, and 6 more.

I noticed in the get call when I do this.researchContentByCompany[0] = result the error is gone but then the data is missing, since this is not an array but only one object with properties.我在执行此操作时在 get 调用中注意到。researchContentByCompany[0] = result 错误消失了,但随后数据丢失了,因为这不是一个数组,而只是一个具有属性的 object。

How can I fix this issue?我该如何解决这个问题?

instead of代替

researchContentByCompany: Observable<ResearchContentByCompany>;

define it as below,定义如下,

researchContentByCompany: ResearchContentByCompany;

because the result is type of ResearchContentByCompany object only.因为结果只是ResearchContentByCompany object 的类型。

暂无
暂无

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

相关问题 “订阅”类型缺少“可观察”类型的以下属性<any> ': _isScalar, source, operator, lift, and 6 more</any> - Type 'Subscription' is missing the following properties from type 'Observable<any>': _isScalar, source, operator, lift, and 6 more 类型 X 缺少类型“Observable”中的以下属性<X> &#39;: _isScalar, source, operator, lift, 和 6 更多 - Type X is missing the following properties from type 'Observable<X>': _isScalar, source, operator, lift, and 6 more 运算符函数<unknown, unknown>缺少“Observable”类型的以下属性:_isScalar、源、运算符、 - OperatorFunction<unknown, unknown> is missing the following properties from type 'Observable': _isScalar, source, operator, 缺少类型“Observable”中的以下属性<PizzaState> - Is missing the following properties from type 'Observable<PizzaState> 输入&#39;可观察的<Service[]> &#39; 缺少类型 &#39;any[]&#39; 的以下属性:length、pop、push、concat 和 25 个更多 - Type 'Observable<Service[]>' is missing the following properties from type 'any[]': length, pop, push, concat, and 25 more 类型'可观察的<string[]> ' 缺少类型 'string[]' 的以下属性:length、pop、push、concat 和另外 25 个</string[]> - Type 'Observable<string[]>' is missing the following properties from type 'string[]': length, pop, push, concat, and 25 more 类型“可观察” <unknown> &#39;缺少&#39;Promise类型的以下属性 <any> - Type 'Observable<unknown>' is missing the following properties from type 'Promise<any> 类型“从不 []”缺少“可观察”类型的以下属性<customer[]> '</customer[]> - type 'never[]' is missing the following properties from type 'Observable<Customer[]>' 类型“订阅”缺少类型“可观察”的以下属性 <StringMap<any> &gt;” - Type 'Subscription' is missing the following properties from type 'Observable<StringMap<any>>' “可观察”类型缺少“用户”类型的以下属性 - Type 'Observable' is missing the following properties from type 'User'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM