[英]Angular2 Google sign
Hi I'm trying Angular2 with Type Script to add a login/logout to/from google by their guide 嗨,我正在尝试使用Type Script的Angular2通过他们的指南向Google添加登录/注销。
In Index.html 在Index.html中
<script src="https://apis.google.com/js/platform.js"></script>
In LoginComponent.ts 在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);
}
Thats works fine for me but when loginSuccess i want to route the view to profile page on that time i am facing the error like: 那对我来说很好,但是当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)
And Also i want the whole login process As Service Or Module to reuse. 而且我还希望整个登录过程作为服务或模块重用。 How Can I create This Whole Google Login Operations As Module or service
我如何创建整个Google登录操作作为模块或服务
Can U give me a code snippet or working demos or suggest me any angular2 module to achieve this. U可以给我一个代码片段或有效的演示吗,或者建议我使用任何angular2模块来实现这一目标。
I also Tried angular2SocialLogin Module But That Also shows error when the production i got error some think I mention in git issue 我还尝试了angular2SocialLogin模块,但是当生产中出现错误时,它也会显示错误,有些错误是我在git问题中提到的
Please Help Me Out of it .Thanks in advance.. 请帮帮我,谢谢。
The error can be fixed by hiding the login button once login is successful. 登录成功后,可以通过隐藏登录按钮来修复该错误。
<div id="g-signin2" style="display: none;"></div>
Refer this answer 参考这个答案
Also I followed this plunkr example and worked fine with me 我也遵循了这个笨拙的例子 ,并与我合作得很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.