【发布时间】: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