【问题标题】:AngularFire2 unsubscribe is not a functionAngularFire2 取消订阅不是一个函数
【发布时间】:2017-12-11 20:51:32
【问题描述】:

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

这是退出方法(按钮点击触发)

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 =>{...

【问题讨论】:

  • 这个问题仍然有效

标签: angular firebase rxjs angularfire2


【解决方案1】:

unsubscribe是订阅接口,由this.profileData.subscribe(...)返回。目前看来this.profileData 被分配给了 Observable。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-06
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 2017-12-18
      相关资源
      最近更新 更多