代码之家  ›  专栏  ›  技术社区  ›  Tristan

TypeError:这个_父订阅。取消订阅不是函数

  •  1
  • Tristan  · 技术社区  · 7 年前

    fbLogin.unsubscribe(); 是问题所在,但即使删除了这两行,错误仍然存在。我使用的是rxjs@^5.5.2。

    ERROR TypeError: this._parentSubscription.unsubscribe is not a function
        at Subscriber._unsubscribeParentSubscription (Subscriber.js:110)
        at Subscriber.error (Subscriber.js:75)
        at auth.ts:54
        at e.b (auth.esm.js:17)
        at Fb (auth.esm.js:20)
        at Bb (auth.esm.js:20)
        at A.g.Xb (auth.esm.js:19)
        at kb (auth.esm.js:13)
        at t.invoke (polyfills.js:3)
        at Object.onInvoke (core.js:4760)
    
    
    //login.ts
    loginWithFacebook(): void{
            let fbLogin = this.authData.loginWithFacebook().subscribe(() => {
                fbLogin.unsubscribe();
                this.navCtrl.setRoot('HomePage');
            }, error => {
                fbLogin.unsubscribe();
                console.log(error);
            });
        }
    
    
    //auth.ts
    loginWithFacebook(): Observable<any> {
            return Observable.create(observer => {
                if (this.platform.is('cordova')) {
                    return this.fb.login(['email', 'public_profile']).then(res => {
                        const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
                        this.afAuth.auth.signInWithCredential(facebookCredential).then(()=> {
                            observer.next();
                        }).catch(error => {
                            console.log(error);
                            observer.error(error);
                        });
                    });
                } else {
                    return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()).then(()=> {
                        observer.next();
                    }).catch(error => {
                        console.log(error);
                        observer.error(error); //this is auth.ts:54
                    });
                }
            });
        }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   t.schoel    7 年前

    中当前不支持异步函数 Observable.create (见 this RxJs issue comment ).

    你可以用 from defer 而是把你的承诺包装成一个可观察的东西。