类型“HttpEvent<Customer>"上不存在属性“data" [英] Property &#39;data&#39; does not exist on type &#39;HttpEvent&lt;Customer&gt;&#39;

查看:18
本文介绍了类型“HttpEvent<Customer>"上不存在属性“data"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的设置

  • api.service(包装 httpClient 模块)
  • 客户服务

api 服务 get 如下所示:

the api service get looks like this:

get<T>(url: string, options?) {
return this.httpClient.get<T>(this.apiUrl + url, this.getOptions(options));}

在我的客户服务中,我有:

in my customer.service I have:

    private fetchCustomer(access_token: String): Observable<Customer> {
      const options = { headers: new HttpHeaders({ Authorization: 'Bearer ' + access_token }) };
      return this.http
        .get<Customer>('customers/me', options)
        .map(res => {
          const customer = res.data;
          customer.access_token = access_token;
          return customer;
        })
        .catch(this.handleError.bind(this));
    }

它给了我这个错误:

[ts]
Property 'data' does not exist on type 'HttpEvent<Customer>'.
Property 'data' does not exist on type 'HttpSentEvent'.

推荐答案

解决方案是使用新的获取json数据的方式....

The solution is to use the new way of getting the json data....

const customer = res['data'];

这篇关于类型“HttpEvent<Customer>"上不存在属性“data"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆