【问题标题】:TypeError: this._parentSubscription.unsubscribe is not a functionTypeError:this._parentSubscription.unsubscribe 不是函数
【发布时间】:2019-02-19 14:13:17
【问题描述】:

当 observable 遇到错误时,是什么导致了这个 TypeError?该错误使我相信由于某种原因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
                });
            }
        });
    }

【问题讨论】:

    标签: typescript ionic-framework rxjs ionic3


    【解决方案1】:

    Observable.create 目前不支持异步函数(请参阅this RxJs issue comment)。

    您可以使用 from 或 defer 代替将您的 Promise 包装为 Observable。

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 2018-05-06
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      相关资源
      最近更新 更多