From 824eab9029ea2fe36b167523c58d455a009d5064 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 7 Dec 2010 16:06:31 -0800 Subject: improving $resource docs --- src/Angular.js | 2 +- src/services.js | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index d5b5144d..ea5d1ea1 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -699,7 +699,7 @@ function concat(array1, array2, index) { * * @param {Object} self Context in which `fn` should be evaluated in. * @param {function()} fn Function to be bound. - * @param {(...*)=} args Optional arguments to be prebound to the `fn` function call. + * @param {...*} args Optional arguments to be prebound to the `fn` function call. * @returns {function()} Function that wraps the `fn` with all the specified bindings. */ function bind(self, fn) { diff --git a/src/services.js b/src/services.js index ef3de549..f7661310 100644 --- a/src/services.js +++ b/src/services.js @@ -888,7 +888,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer){ /** * @workInProgress - * @ngdoc service + * @ngdoc function * @name angular.service.$resource * @requires $xhr * @@ -934,6 +934,33 @@ angularServiceInject('$xhr.cache', function($xhr, $defer){ expect(newCard.id).toEqual(789); * * + * The object returned from this function execution is a resource "class" which has "static" method + * for each action in the definition. + * + * Calling these methods invoke `$xhr` on the `url` template with the given `method` and `params`. + * When the data is returned from the server then the object is an instance of the resource type and + * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD + * operations (create, read, update, delete) on server-side data. + +
+ var User = $resource('/user/:userId', {userId:'@id'});
+ var user = User.get({userId:123}, function(){
+ user.abc = true;
+ user.$save();
+ });
+
+ *
+ * It's worth noting that the callback for `get`, `query` and other method gets passed in the
+ * response that came from the server, so one could rewrite the above example as:
+ *
+
+ var User = $resource('/user/:userId', {userId:'@id'});
+ User.get({userId:123}, function(u){
+ u.abc = true;
+ u.$save();
+ });
+
+ *
*
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
* `/user/:username`.
@@ -964,20 +991,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer){
'delete': {method:'DELETE'} };
*
*
- * @returns {Object} A resource "class" which has "static" method for each action in the definition.
- * Calling these methods invoke `$xhr` on the `url` template with the given `method` and
- * `params`. When the data is returned from the server then the object is an instance of the
- * resource type and all of the non-GET methods are available with `$` prefix. This allows you
- * to easily support CRUD operations (create, read, update, delete) on server-side data.
-
-
- var User = $resource('/user/:userId', {userId:'@id'});
- var user = User.get({userId:123}, function(){
- user.abc = true;
- user.$save();
- });
-
- *
+ * @returns {Object} A resource "class".
*
* @example