Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created September 28, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swimburger/52b84e0309b217439cc7 to your computer and use it in GitHub Desktop.
Save Swimburger/52b84e0309b217439cc7 to your computer and use it in GitHub Desktop.
Example directive for google sign in button
<!doctype html>
<html lang="en" ng-app="app" ng-controller="MainController">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="google-signin-client_id" content="859037623-6vp83186d483245qiv0lredmp55im54r.apps.googleusercontent.com">
</head>
<body>
<google-sign-in-button button-id="uniqueid" options="options"></google-sign-in-button>
<script src="https://apis.google.com/js/platform.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script>
<script>
angular.module('app',[])
.controller('MainController',['$scope', function ($scope) {
//for more options visit https://developers.google.com/identity/sign-in/web/reference#gapisignin2renderwzxhzdk114idwzxhzdk115_wzxhzdk116optionswzxhzdk117
$scope.options={
'onsuccess':function(response){
console.log(response);
}
}
}])
.directive('googleSignInButton',function(){
return {
scope:{
buttonId:'@',
options:'&'
},
template: '<div></div>',
link: function(scope, element, attrs){
var div = element.find('div')[0];
div.id=attrs.buttonId;
gapi.signin2.render(div.id,scope.options());//render a google button, first argument is an id, second options
}
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment