Skip to content

Instantly share code, notes, and snippets.

@cameri
Created February 14, 2014 12:17
Show Gist options
  • Save cameri/9000081 to your computer and use it in GitHub Desktop.
Save cameri/9000081 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="userctrl.js"></script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
</head>
<body>
<div ng-controller="UserCtrl">
<h2>New User</h2>
<form ng-submit="insert()">
<input type="text" ng-model="username" size="50"><br>
<input type="text" ng-model="password" size="50"><br>
<input type="submit" class="btn" value="Post">
</form>
<h2>Users</h2>
<ul>
<li ng-repeat="user in users">
{{user.id}} {{user.username}}: {{user.password}}
</ul>
</div>
</body>
</html>
var UserApp = angular.module('UserApp', []);
UserApp.controller('UserCtrl', function ($scope) {
$scope.users = [
{
"id": "123123",
"username": "Testo",
"password": "123",
}
];
$scope.insert = function() {
var user = {
"username": $scope.username,
"password": $scope.password
};
console.log(user);
console.log(gapi);
gapi.client.userendpoint.insertUser(user).execute();
};
$scope.list = function() {
gapi.client.userendpoint.listUser().execute(function(resp) {
$scope.users = resp.items;
$scope.$apply();
});
};
});
function init() {
var endpoint = 'https://.../_ah/api';
gapi.client.load('userendpoint', 'v1', function() {
angular.bootstrap(document, [ "UserApp"]);
console.log("initialized");
console.log(angular);
}, endpoint);
}
//window.init = function() {
// $scope.$apply($scope.load_user_lib);
//};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment