2017-02-05 3 views
1

私はGoogle認証ボタンを追加したいと思います。Angular2 - ログインwith gapi

私はこのメタ持っているindex.htmlファイルで

<meta name="google-signin-scope" content="profile email"> 
<meta name="google-signin-client_id" content="xxxxx.apps.googleusercontent.com"> 
<script src="https://apis.google.com/js/platform.js" async defer></script> 

とルートcompoponentに私はこの1つ持っている:

ngOnInit() { 
    console.log('rvep ngOnInit'); 
    gapi.load('auth2', function() { 
    console.log('gapi.load'); 
    var auth2 = gapi.auth2.init({ 
     client_id: 'xxxx.apps.googleusercontent.com' 
    }); 

    if (auth2.isSignedIn.get()) { 
     auth2.signIn(); 
    } 

    console.log('is user signed in: ' + auth2.isSignedIn.get()); 
    }); 
} 

とlogin.componentで:

// Angular hook that allows for interaction with elements inserted by the 
// rendering of a view. 
ngAfterViewInit() { 
    // Converts the Google login button stub to an actual button. 
    gapi.signin2.render("rvepGoogleSignin", 
    { 
    "onSuccess": this.onSuccess, 
    "scope": "profile", 
    "theme": "dark" 
    }); 
} 

ボタンは表示されません。私は間違っている?ありがとう

答えて

0

これはあなたの.htmlファイルですか?

<div style="float: left; width: 33%;"> 
    <div id="my-signin2" (data-onsuccess)="onSignIn"></div> 
    <span>&#8203;</span> 
</div>