Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created February 11, 2012 01:57
Show Gist options
  • Save vojtajina/1795233 to your computer and use it in GitHub Desktop.
Save vojtajina/1795233 to your computer and use it in GitHub Desktop.
Angular: 0.9.19 resource example
)]}',
[{
"name": "one"
}, {
"name": "two"
}]
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.angularjs.org/0.9.19/angular-0.9.19.js" ng:autobind></script>
<title></title>
<script type="text/javascript">
function Ctrl($resource) {
var R = $resource('/tmp/:some');
this.save = function(resource) {
resource.$save(function() {
console.log('SUCCESS save');
}, function() {
console.log('ERROR save');
});
};
this.anotherSave = function(resource) {
R.save(resource, function() {
console.log('SUCCESS another save');
}, function() {
console.log('ERROR another save');
});
};
this.load = function() {
this.items = R.query({some: '12.json'}, function() {
console.log('SUCCESS query');
}, function() {
console.log('ERROR query');
});
};
}
</script>
</head>
<body ng:controller="Ctrl">
<a ng:click="load()">LOAD</a>
<div ng:repeat="i in items">
{{i.name}}:
<a ng:click="save(i)">SAVE</a> | <a ng:click="anotherSave(i)">ANOTHER</a>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment