2017-02-05 3 views
1

Ich möchte Google-Authentifizierung Schaltfläche hinzufügen.Angular2 - Login mit gapi

In der Datei index.html habe ich diese Meta:

<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> 

und in der Wurzel compoponent Ich habe diese ein:

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()); 
    }); 
} 

und im 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" 
    }); 
} 

Aber die Schaltfläche funktioniert nicht. Was ich falsch mache? Danke

Antwort

0

Haben Sie das ist Ihre .html-Datei?

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