0
gapi.signin2.renderを使用して、カスタムGoogleログインボタンをAngularで作成しています。以前は別のプロジェクトで同じコードが使用されていましたが、現在は機能していないため、その理由を把握することはできません。私のコードは、このgapi.signin2.renderはAngularアプリでonsuccessメソッドを呼び出しません
index.htmlを
<meta name="google-signin-client_id" content="xxx.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js"></script>
...
<div ng-controller="loginController">
<google-sign-in-button button-id="uniqueid" options="googleOptions"></google-sign-in-button>
</div>
loginController.js
function loginController($scope, $rootScope) {
$scope.googleOptions = {
'width': 200,
'height': 50,
'theme': 'dark',
'onsuccess': success,
'onfailure': function() {
console.log('failed');
}
}
console.log($scope.googleOptions); //prints out options
}
function success(response) {
var AUTH_TOKEN = response.getAuthResponse().id_token;
$rootScope.AUTH_TOKEN = AUTH_TOKEN;
console.log('Google token successfully retrieved for user ->', $rootScope.AUTH_TOKEN);
}
とディレクティブのように見える :
function googleSignInButton() {
return {
scope: {
buttonId: '@',
options: '&'
},
template: '<div></div>',
link: function (scope, element, attrs) {
var div = element.find('div')[0];
div.id = attrs.buttonId;
// console.log(`div.id --> ${div.id}`);
console.log(`Google options inside google sign in directive: ${scope.options()}`);
console.log(scope.options());
console.log('div.id->',div.id);
gapi.signin2.render(div.id, scope.options()); //render a google button, first argument is an id, second options
// debugger;
}
};
}
私はこのpost Aからこのコードスニペットを見つけました以前はうまくいきました。なぜコールバックに当たらないのか分かりません。