【问题标题】:Angular2 Google signAngular2谷歌标志
【发布时间】:2017-07-30 06:01:25
【问题描述】:

您好,我正在尝试使用带有 Type Script 的 Angular2 通过their guide向/从谷歌添加登录/注销

在 Index.html 中

 <script src="https://apis.google.com/js/platform.js"></script>

在 LoginComponent.ts 中

declare const gapi: any;

ngAfterViewInit() {
  gapi.signin2.render(
  this.googleLoginButtonId,
  {"onSuccess": this.onGoogleLoginSuccess,"scope": "profile",
    "theme": "dark"},function (error) {
   console.log(JSON.stringify(error, undefined, 2));
  });

}

      onGoogleLoginSuccess = (loggedInUser) => {
var profile = loggedInUser.getBasicProfile();
       this.auth.LoginSuccess(loggedInUser);
      }

这对我来说很好,但是当 loginSuccess 我想在那个时候将视图路由到个人资料页面时,我面临如下错误:

Uncaught TypeError: Cannot read property 'style' of null
    at G_ (cb=gapi.loaded_0:282)
    at H_.<anonymous> (cb=gapi.loaded_0:285)
    at Function.<anonymous> (cb=gapi.loaded_0:155)
    at MessagePort.c.port1.onmessage (cb=gapi.loaded_0:73)

而且我希望整个登录过程作为服务或模块重用。如何将整个 Google 登录操作创建为模块或服务

你能给我一个代码 sn-p 或工作演示或建议我任何 angular2 模块来实现这一点。

我也尝试过 angular2SocialLogin 模块,但这也显示了错误,当我收到错误时,有些人认为我在 git issue 中提到过

请帮帮我。在此先感谢..

【问题讨论】:

    标签: angular typescript google-api google-api-js-client angular2-modules


    【解决方案1】:

    登录成功后,可以通过隐藏登录按钮来修复错误。

     <div id="g-signin2" style="display: none;"></div>
    

    参考this answer

    我也关注了这个plunkr example 并与我合作得很好

    【讨论】:

    • 谢谢你 Thabung,但我希望谷歌登录为服务或模块,我该如何实现,请帮助我......
    • 您好,谢谢您的回答,我从link找到了解决方案
    猜你喜欢
    • 2018-07-22
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多