首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError: this._parentSubscription.unsubscribe不是一个函数

TypeError: this._parentSubscription.unsubscribe不是一个函数
EN

Stack Overflow用户
提问于 2018-09-14 18:28:18
回答 1查看 670关注 0票数 1

当可观察到的结果遇到错误时,是什么导致了这个TypeError?这个错误使我相信,出于某种原因,fbLogin.unsubscribe();是问题所在,但即使删除了这两行,错误仍然存在。我使用的是rxjs@^5.5.2。

代码语言:javascript
复制
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
                });
            }
        });
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-24 07:11:27

异步函数目前在Observable.create中不支持(参见这个RxJ发布评论)。

您可以使用fromdefer来将您的承诺包装为可观察的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52337488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档