'HttpEvent< Customer>'类型中不存在属性'data' [英] Property 'data' does not exist on type 'HttpEvent<Customer>'

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

问题描述

我有这样的设置


  • api.service(包装httpClient模块)

  • customer.service

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));}

在我的customer.service中我有:

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));
    }

它给我这个错误:

and it give me this error:

[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&lt; Customer&gt;'类型中不存在属性'data'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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