Skip to content

Instantly share code, notes, and snippets.

@menacestudio
Created December 9, 2014 05:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save menacestudio/d737e52943025c495e67 to your computer and use it in GitHub Desktop.
Angular CRUD
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.3.5" src="https://code.angularjs.org/1.3.5/angular.js"></script>
<script src="https://code.angularjs.org/1.3.5/angular-route.js" data-semver="1.3.5" data-require="angular-route@*"></script>
<script data-require="angular-resource@1.3.5" data-semver="1.3.5" src="https://code.angularjs.org/1.3.5/angular-resource.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
<body ng-app="app">
<div id="wrapper" ng-controller="Ctrl as vm" ng-init="vm.initialize()">
<h1>{{ vm.title }}</h1>
</div>
</body>
</html>
(function(){
var app = angular.module('app', ['ngResource']);
})();
(function(app){
app.factory('aService', ['$resource', function($resource){
return $resource('/api/aService/:id', {id:'@id'}, {
'update': { method:'PUT' }
});
}]);
})(angular.module('app'));
(function(app) {
app.controller('Ctrl', ['$scope', 'aService',
function($scope, aService){
var vm = this;
vm.title = 'Hello';
vm.id = 1;
vm.initialize = function(){
vm.user = aService.get({ id: vm.id}, function(){});
};
vm.update = function(){
vm.user.$update({id: 1});
};
vm.delete = function(id){
aService.delete({id: id}, function(){});
};
}])
})(angular.module('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment