如何取消 FirebaseObjectObservable 订阅?

Jus*_*s10 2 rxjs angularfire2 angular

我知道在其他情况下,我可以使用 unsubscribe() 关闭 observable,但据我所知 FirebaseObjectObservable 似乎没有该功能。我怎样才能关闭它?

this.rock = this.af.database.object('/rocks/'+ rockKey);
this.rock.subscribe(obj=>{
  console.log("Can't stop the rock");
});
Run Code Online (Sandbox Code Playgroud)

小智 5

你不会取消订阅 observable;您取消订阅。这与 Firebase observables 无关。

this.subscription = this.rock.subscribe(obj=>{
  console.log("Can't stop the rock");
});

this.subscription.unsubscribe();
Run Code Online (Sandbox Code Playgroud)