【发布时间】:2022-02-05 08:49:10
【问题描述】:
我使用我的 Angular 服务发出了一个 http 发布请求,我正在等待布尔返回。 但是对于没有内容的 204 http 代码响应,角度返回 false。
这是我的服务功能:
public create(
base_price: number,
domain_id: number|null
): Observable<boolean> {
this.isLoadingSubject.next(true);
return this.http.post<boolean>(`${API_URL}/pictures`, {
base_price,
domain_id
})
.pipe(finalize(() => this.isLoadingSubject.next(false)))
}
还有我的组件:
submit() {
this.hasError = false;
const create = this.pictureService
.create(
this.f.base_price.value,
this.f.domain_id.value,
)
.pipe(first())
.subscribe((result: boolean) => {
this.hasError = !result;
});
this.unsubscribe.push(create);
}
所以 create 函数返回 false,我没有找到解决方案来捕获 204 状态。
谢谢
【问题讨论】:
标签: angular angular-httpclient angular-http