【问题标题】:Http Client Angular 6Http 客户端 Angular 6
【发布时间】:2019-12-13 21:06:13
【问题描述】:

我正在尝试输入我的请求的返回结果,但是我收到以下错误:

类型 'Observable' 不可分配给类型 “可观察”。类型“ArrayBuffer”缺少 'AccountModel[]' 类型的以下属性:length、pop、push、 concat,还有 25 个

我的要求如下:

 getAccounts(): Observable<AccountModel[]>
    {
        return this.http.get(`${this._configShared.getApiUrl()}`, this.httpOptions);
    }

我哪里出错了?

提前谢谢...

我做了以下,它也没有工作:

getAccounts(): Observable<AccountModel[]>
    {
        return this.http.get<AccountModel[]>(`${this._configShared.getApiUrl()}`, this.httpOptions);
    }

错误:

Type 'Observable>' 不可分配给 type “可观察”。类型“HttpEvent”是 不可分配给类型“AccountModel[]”。 类型“HttpSentEvent”缺少类型“AccountModel[]”中的以下属性:长度、弹出、推送、连接等 26 个。

【问题讨论】:

  • 你从哪里导入Observable
  • 请分享您的导入语句和 httpOptions
  • httpOptions 是一个对象 any。从 Observable 的导入是:'import { Observable } from "rxjs";'

标签: angular http request


【解决方案1】:

改变

return this.http.get(`${this._configShared.getApiUrl()}`, this.httpOptions);

return this.http.get<AccountModel[]>(`${this._configShared.getApiUrl()}`, this.httpOptions);

【讨论】:

  • 我这样做了,但也没有用。我用新错误更新了我的问题
猜你喜欢
  • 2019-01-27
  • 1970-01-01
  • 1970-01-01
  • 2019-01-22
  • 1970-01-01
  • 2019-09-19
  • 1970-01-01
  • 2018-05-17
  • 1970-01-01
相关资源
最近更新 更多