我一直收到取消订阅不是函数的错误。我正在使用rxjs@5.0.0-beta.12。
这些是我的导入声明:
import { TimerObservable } from 'rxjs/observable/TimerObservable';
import 'rxjs/add/operator/take';
这是有问题的TimerObservable:
countdown = TimerObservable.create(0, 1000).take(6);
这将启动计时器:
startCountdownTimer(): void {
this.countdown.subscribe(
i => this.timeRemaining = (5 - i).toString(),
null,
() => this.toDelete = -1)
}
这个,这不起作用:
cancelCountdownTimer(): void {
this.countdown.unsubscribe();
}
答案 0 :(得分:0)
subscribe
的来电者收到subscription:
startCountdownTimer(): void {
this.subscription = this.countdown.subscribe(
i => this.timeRemaining = (5 - i).toString(),
null,
() => this.toDelete = -1);
}
有unsubscribe
方法:
cancelCountdownTimer(): void {
this.subscription.unsubscribe();
}