【发布时间】:2019-05-27 13:07:24
【问题描述】:
我有两个函数,我需要在第一个函数中订阅 observable,在第二个函数中取消订阅。但在我的代码中,我无法从第二个函数访问 observable,因为它不在其范围内。
这是我的功能:
start() {
this.max = this.duration;
const interval = Observable.interval(this.selectedSprint.duration);
interval
.takeWhile(_ => !this.isFinished)
.do(i => this.current += 1)
.subscribe();
}
stop() {
// here I need to unsybscribe to the observable
this.dialogService.openConfirmDialog('do you want to stop ?')
.afterClosed().subscribe((result: boolean) => {
if (result) {
// if true logic
}
});
}
【问题讨论】:
标签: angular rxjs angular2-observables