Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:googleAuth.then不是函数_Javascript_Angular_Typescript_Google Api_Google Authentication - Fatal编程技术网

Javascript 未捕获类型错误:googleAuth.then不是函数

Javascript 未捕获类型错误:googleAuth.then不是函数,javascript,angular,typescript,google-api,google-authentication,Javascript,Angular,Typescript,Google Api,Google Authentication,我已经用Google身份验证运行Angular 5应用程序一段时间了,然后这个错误突然出现在prod和dev上。登录成功,我得到了一个GoogleAuth对象。我可以获得用户详细信息,但随后我得到了这个错误: Uncaught TypeError: googleAuth.then is not a function 这是代码块_googleAuth是一个调用init的服务 this._googleAuth.getAuth() .subscribe(googleAuth =>

我已经用Google身份验证运行Angular 5应用程序一段时间了,然后这个错误突然出现在prod和dev上。登录成功,我得到了一个GoogleAuth对象。我可以获得用户详细信息,但随后我得到了这个错误:

Uncaught TypeError: googleAuth.then is not a function
这是代码块_googleAuth是一个调用init的服务

this._googleAuth.getAuth()
      .subscribe(googleAuth => {

        // TODO
        console.log('user signedIn: ', googleAuth.isSignedIn.get()); // this returns true

        const self = this;
        googleAuth.then(function() { // error occurs here
          if (googleAuth.isSignedIn.get()) {
            ...
          } 
...
我已将打字更新为:

@类型/gapi:0.0.35, @types/gapi.auth2:0.0.47

下面是getAuth函数,它似乎仍然有效:

public getAuth(): Observable<GoogleAuth> {
        if (!this.GoogleAuth) {
            return this.googleApi.onLoad().mergeMap(() => this.loadGapiAuth());
        }
        return Observable.of(this.GoogleAuth);
    }
我已经检查了打字和GoogleAuth。然后在那里定义。为什么我可以得到一个GoogleAuth对象但不能调用。那么


GoogleAuth.then的谷歌文档在这里:

我现在还不清楚为什么这会成为一个错误,但我找到了一个可能的解决方案。TypeScript包装服务已经在调用了。然后在gapi.auth2.init之后,所以看起来我调用了它两次。我已经取下了那张支票,它似乎起作用了。我仍然需要运行我的测试套件,但到目前为止它看起来很有希望。

GoogleAuth是一个承诺吗?@connexo在typings中,GoogleAuth被定义为一个单例类。getAuth以observablegapi的形式返回GoogleAuth对象。auth2.initparams初始化GoogleAuth对象。在调用gapi.auth2.GoogleAuth的方法之前,必须调用此方法@康奈索是的,我在问题中提到过。getAuth在loadGapiAuth中调用init,它似乎可以工作,因为我获得了用户详细信息和signedIn状态。然而,intellisense中出现的.then函数也抛出了错误。非常奇怪。你的getAuth代码看起来不像Javascript。