AngularFire2取消订阅不是一个功能

时间:2017-12-11 20:51:33

标签: angular firebase rxjs angularfire2

我正在尝试编写一个注销方法。在退出之前我试图取消订阅我以前的订阅,否则我会收到许多订阅和权限错误

这是注销方法(按钮点击会触发这个)

console.log(this.profileData);
this.profileData.unsubscribe();

  this.app.auth().signOut().then(function() {

    alert("you successfully signed out");

  }, function(error) {
  alert("error");
  });

这就是我订阅的方式

    this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).valueChanges());
  this.profileData.subscribe(profile =>{...

enter image description here

2 个答案:

答案 0 :(得分:1)

unsubscribe是订阅的接口,由this.profileData.subscribe(...)返回。目前似乎this.profileData已分配给Observable。

答案 1 :(得分:0)

您正在尝试取消订阅观察,而不是订阅。 你应该这样做:

this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).valueChanges());
this.profileSubcription = this.profileData.subscribe(profile =>{...});

console.log(this.profileData);
this.profileSubcription.unsubscribe();

this.app.auth().signOut().then(function() {

 alert("you successfully signed out");

}, function(error) {
 alert("error");
});