繁体   English   中英

Angular2 Google标志

[英]Angular2 Google sign

嗨,我正在尝试使用Type Script的Angular2通过他们的指南向Google添加登录/注销。

在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登录操作作为模块或服务

U可以给我一个代码片段或有效的演示吗,或者建议我使用任何angular2模块来实现这一目标。

我还尝试了angular2SocialLogin模块,但是当生产中出现错误时,它也会显示错误,有些错误是我在git问题中提到的

请帮帮我,谢谢。

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

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

参考这个答案

我也遵循了这个笨拙的例子 ,并与我合作得很好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM