如何在 rxjs 中取消订阅我漂亮的 TimerObservable

How to unsubscribe from my nifty TimerObservable in rxjs

我一直收到取消订阅不是函数的错误。我正在使用 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();
}

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();
}