[英]google sign-in with angular2 and typescript - where to get gapi?
[英]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問題中提到的
請幫幫我,謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.