Skip to content

Instantly share code, notes, and snippets.

@arantius
Created March 21, 2011 19:58
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 arantius/880088 to your computer and use it in GitHub Desktop.
Save arantius/880088 to your computer and use it in GitHub Desktop.
angular .save() / .get() confusion test case
application: angular-resource-save-test
version: 1
runtime: python
api_version: 1
handlers:
- url: /
static_files: index.html
upload: index.html
- url: /foo.json
static_files: foo.json
upload: foo.json
{"name": "bar", "obj": {"value": 42}}
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
<title>Angular Save Resource Test</title>
</head>
<body>
<div ng:controller="FooCtrl">
<input type="text" name="foo.name"><br>
obj.value: <input type="text" name="foo.obj.value"><br>
<button ng:click="save()">Save</button>
<pre>foo: {{foo}}</pre>
<pre>obj: {{obj}}</pre>
</div>
<script src="http://code.angularjs.org/angular-0.9.13.min.js" ng:autobind></script>
<script type="text/javascript">
function FooCtrl($resource) {
this.Foo = $resource('./foo.json');
this.foo = {};
this.Foo.get(angular.bind(this, this.loadFooCallback));
}
FooCtrl.$inject = ['$resource'];
FooCtrl.prototype.loadFooCallback = function(foo) {
this.foo = foo;
this.obj = foo.obj;
this.obj.value = -1;
}
FooCtrl.prototype.save = function() {
this.foo.$save();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment