【发布时间】:2018-08-25 15:16:43
【问题描述】:
我收到一个来自 http get 调用的客户端:
getClientById(clientId): Observable<Client>{
let params = new HttpParams().set('clientId', clientId);
return this.httpClient.get<Client>('http://localhost:3000/clients/getClientById', { responseType: 'json', params: params });
}
我的客户端类如下所示:
export class Client {
name= '';
familyName = '';
public toString(){
return this.name+ " " + this.familyName;
}
}
我的问题是当我调用 toString() 方法时,我收到一个 [object object]。
我做错了什么?
【问题讨论】:
-
听起来你得到的数据不是你想的那样
-
我认为它是一个客户,因为我可以做 myClient.name 并且它可以工作......
-
您能告诉我们您的查询结果吗?也可以试试: let result = " "+this.name+ " " + this.familyName;返回结果;
-
在 toString() 方法中添加调试行以显示所有变量
-
你在使用 HttpClient 吗?还是您使用的是 Http 但变量名不同?