2017-03-09 49 views
0

你好我想Angular2与脚本类型由their guideAngular2谷歌签署

登录/注销从谷歌添加/ 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) 

,也是我希望整个登录过程作为服务或模块重用。我如何创建这整个谷歌登录操作作为模块或服务

你可以给我一个代码片段或工作演示或建议我任何angular2模块来实现这一点。

我也试过angular2SocialLogin模块,但也显示错误,当我制作了一些错误我想提git issue

请大家帮我出它提前.Thanks ..

回答

2

的错误可能是登录成功后,通过隐藏登录按钮进行修复。

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

参考this answer

我也遵循了这一plunkr example和我一起工作的罚款

+0

谢谢Thabung但我希望谷歌登录的服务或模块我怎么能做到这一点请帮助我... –

+0

嗨,谢谢你的回答,我从这个[link]找到解决方案(https://stackoverflow.com/questions/35096271/how-to-implement-social-authentication-for-an-api) –