您好,我正在尝试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 Login Operations创建为模块或服务
你能给我一个代码片段或工作演示或建议我任何angular2模块来实现这一点。
我也尝试过angular2SocialLogin模块,但当我在git issue中提到生产时,也会显示错误。
请提前帮我摆脱它.Thanks ..
发布于 2017-03-09 18:33:05
该错误可以通过在登录成功后隐藏登录按钮来修复。
<div id="g-signin2" style="display: none;"></div>另外,我遵循了这个plunkr example,并且和我一起工作得很好
https://stackoverflow.com/questions/42692172
复制相似问题