在我的角度应用程序中,我希望能够取消与Rxjs进行的http请求。场景:取消rxjs中的http订阅
isComponentAlive = true;
onSave() {
this.service.save(this.formValue).takeWhile(() => this.isComponentAlive).subscribe();
}
ngOnDestroy() {
this.isComponentAlive = false;
}
比我有一个取消按钮导航到另一条路线。我想取消挂起的http请求,但这种方式不起作用。我想做更清楚的事情,然后调用取消订阅所有的http请求订阅
'takeWhile'不能用于取消一个挂起的HTTP请求,因为它所需要的谓词被称为[当它收到一个值时](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-takeWhile) - 即当HTTP请求时est发出回应。 – cartant