【发布时间】:2018-05-05 19:01:11
【问题描述】:
我将 Angular 4 与 .net 核心 WEB API 挂钩。
Web API 正在根据传入的 Id 返回字符串中的 CustomerName。
这是 Angular 4 中的服务方法。 我知道 angular/http 必须返回一个 Observable,因为它是一个异步调用。
但是我该如何返回一个字符串呢? 或者如何从调用方法访问 Observable 对象中的数据?
getCustomerName(id: number): Observable<any>{
return this._http.get(this.baseUrl + 'api/getCustomerName/' + id )
.map((response: Response) => <any>response.json() )
.catch(this.handleError);
}
【问题讨论】:
标签: angular observable