【发布时间】:2019-05-09 15:47:02
【问题描述】:
有一个返回简单字符串的 api 方法。我正在我的角度服务中实现一个需要返回可观察对象的方法
简单的字符串不会直接映射到 observable。如何使用 api 的简单字符串结果返回 observable?
public setLineItemListApproval(lines : OrderLinesModel) : Observable<string>{
let actionUrl = this.apiBaseURL + '/mycontroller/actionmethod1';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.httpClient.post<string>(actionUrl, lines, httpOptions).pipe(catchError(this.handleError));
}
【问题讨论】:
-
你想在哪里退货?在某些组件中?或者在同一个服务中
标签: angular rxjs observable angular-services