我正在使用gapi.signin2.render在Angular中创建自定义Google登录按钮。以前在另一个项目中使用相同的代码,但它现在无法正常工作,无法弄清楚原因。 我的代码看起来像这样
的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找到了这个代码片段,它运行得很好。我不知道为什么它现在没有达到回调。
答案 0 :(得分:0)