【发布时间】:2018-05-01 13:23:42
【问题描述】:
official Angular HttpClient documentation 给出了以下示例,用于向某个后端服务器发出 POST 请求。
/** POST: add a new hero to the database */
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
.pipe(
catchError(this.handleError('addHero', hero))
);
}
但我很困惑为什么 Observable 会在 POST 请求中返回 Hero 数据,或者根本不是成功代码的数据。我理解为什么 GET 请求会使用类型断言,但不太明白它是如何工作的。
【问题讨论】:
标签: angular typescript http post