【发布时间】:2017-11-06 20:52:04
【问题描述】:
我正在使用来自'@angular/common/http' 的新HttpClient。我的组件和服务设置如下:
component.ts
public async saveComment() {
this._service.postComment(this.comment);
// I want to wait for the post to complete and then update my comments list below
this.comments = await this._service.getComments();
}
service.ts
public postComment(comment: string) {
this._http.post(this.serviceUrl, { comment })
.subscribe(
response => {
console.log(response);
});
}
post 不返回任何内容。它只在成功时返回200,如果不成功则返回错误状态。
如何等待我的组件在我的服务中调用 post 的 HTTP 响应状态?
【问题讨论】:
标签: angular