I recently went through a tutorial on integrating Google sign-in with my AngularJS app. Following the tutorial instructions, I added the Google button in the following manner:
First, I included the meta tag in the head section:
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
Next, I inserted the button itself:
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Initially, I directly copied the onSignIn
method (a generic handler provided in the tutorial) into a script tag, and it worked. Now, I want to move this method into an Angular controller. So, I created a controller like this:
app.controller('GoogleCtrl', function() {
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
}
Then, I enclosed the button within a div:
<div ng-controller="GoogleCtrl">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
Unfortunately, my code is not able to reach the onSignIn
method now, and I am currently troubleshooting the issue to find a solution.