Angular CLI构建后如何解决TypeError

时间:2018-03-18 17:14:28

标签: angular angular-cli angular5 google-login

我已在我的项目中集成了Google登录Api。它在开发阶段工作正常,应用程序构建成功,没有任何错误。但是,当我运行构建文件,并尝试在我的浏览器中登录时,我收到以下错误:

  

TypeError:无法读取属性' signIn'未定义的

我的组件代码

declare const gapi:any;

export class AppComponent {
    public googleInit() {
        let that = this;
        gapi.load('auth2', function () {
          that.auth2 = gapi.auth2.init({
            client_id: 'CLIENT_ID',
            cookiepolicy: 'single_host_origin',
            scope: 'profile email'
          });
        });
      }
    public auth2:any;
    loginGoogle(){
        let seed = this;
        this.auth2.signIn().then(function(res){
            console.log(res)
        });

      }

    ngAfterViewInit() {
        this.googleInit();
      }
}

我的模板文件

<button (click)="loginGoogle()">Login</button>

如何在我的代码中解决TypeError?上述编码在开发环境中工作正常。

1 个答案:

答案 0 :(得分:0)

试试这个

/* config/express.js */
var express = require('express');
module.exports = function() {
  var app = express();
  app.set('port', 3000);
  return app;
};


/* server.js */
var http = require('http');
var app = require('./config/express')(); // Notice the additional () here

http.createServer(app).listen(app.get('port'), function() {
    console.log("Express Server Runing on port"+ app.get('port'));
});