【发布时间】:2017-11-21 16:37:58
【问题描述】:
在我的 Angular 应用程序中,我希望能够取消使用 Rxjs 发出的 http 请求。场景:
isComponentAlive = true;
onSave() {
this.service.save(this.formValue).takeWhile(() => this.isComponentAlive).subscribe();
}
ngOnDestroy() {
this.isComponentAlive = false;
}
比我有一个取消按钮导航到另一条路线。我想取消一个挂起的 http 请求,但这种方式不起作用。我想做一些更清楚的事情,然后取消订阅我所有的 http 请求订阅
【问题讨论】:
-
takeWhile不能用于取消挂起的 HTTP 请求,因为它采用的谓词称为 when it receives a value - 即当 HTTP 请求发出响应时。