【发布时间】:2018-01-23 17:07:17
【问题描述】:
我有这样的设置
- api.service(包装httpClient模块)
- 客户服务
api 服务获取如下:
get<T>(url: string, options?) {
return this.httpClient.get<T>(this.apiUrl + url, this.getOptions(options));}
在我的 customer.service 中,我有:
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'.
【问题讨论】:
-
在您的 fetchCustomer 方法中 this.http 是否引用您的 api 服务?或 http 客户端
-
它使用我的 api 服务