|
1 | 1 | /** |
2 | | - * @license AngularJS v1.0.0rc5 |
3 | | - * (c) 2010-2012 AngularJS http://angularjs.org |
| 2 | + * @license AngularJS v1.0.0rc6 |
| 3 | + * (c) 2010-2012 Google, Inc. http://angularjs.org |
4 | 4 | * License: MIT |
5 | 5 | */ |
6 | 6 | (function(angular) { |
|
106 | 106 | }); |
107 | 107 |
|
108 | 108 | // We can retrieve a collection from the server |
109 | | - var cards = CreditCard.query(); |
110 | | - // GET: /user/123/card |
111 | | - // server returns: [ {id:456, number:'1234', name:'Smith'} ]; |
112 | | -
|
113 | | - var card = cards[0]; |
114 | | - // each item is an instance of CreditCard |
115 | | - expect(card instanceof CreditCard).toEqual(true); |
116 | | - card.name = "J. Smith"; |
117 | | - // non GET methods are mapped onto the instances |
118 | | - card.$save(); |
119 | | - // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'} |
120 | | - // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
121 | | -
|
122 | | - // our custom method is mapped as well. |
123 | | - card.$charge({amount:9.99}); |
124 | | - // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'} |
125 | | - // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
| 109 | + var cards = CreditCard.query(function() { |
| 110 | + // GET: /user/123/card |
| 111 | + // server returns: [ {id:456, number:'1234', name:'Smith'} ]; |
| 112 | +
|
| 113 | + var card = cards[0]; |
| 114 | + // each item is an instance of CreditCard |
| 115 | + expect(card instanceof CreditCard).toEqual(true); |
| 116 | + card.name = "J. Smith"; |
| 117 | + // non GET methods are mapped onto the instances |
| 118 | + card.$save(); |
| 119 | + // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'} |
| 120 | + // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
| 121 | +
|
| 122 | + // our custom method is mapped as well. |
| 123 | + card.$charge({amount:9.99}); |
| 124 | + // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'} |
| 125 | + }); |
126 | 126 |
|
127 | 127 | // we can create an instance as well |
128 | 128 | var newCard = new CreditCard({number:'0123'}); |
@@ -324,7 +324,7 @@ angular.module('ngResource', ['ng']). |
324 | 324 | } |
325 | 325 |
|
326 | 326 | forEach(actions, function(action, name) { |
327 | | - var isPostOrPut = action.method == 'POST' || action.method == 'PUT'; |
| 327 | + var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH'; |
328 | 328 | Resource[name] = function(a1, a2, a3, a4) { |
329 | 329 | var params = {}; |
330 | 330 | var data; |
@@ -355,7 +355,7 @@ angular.module('ngResource', ['ng']). |
355 | 355 | } |
356 | 356 | case 1: |
357 | 357 | if (isFunction(a1)) success = a1; |
358 | | - else if (isPostOrPut) data = a1; |
| 358 | + else if (hasBody) data = a1; |
359 | 359 | else params = a1; |
360 | 360 | break; |
361 | 361 | case 0: break; |
@@ -415,7 +415,7 @@ angular.module('ngResource', ['ng']). |
415 | 415 | throw "Expected between 1-3 arguments [params, success, error], got " + |
416 | 416 | arguments.length + " arguments."; |
417 | 417 | } |
418 | | - var data = isPostOrPut ? this : undefined; |
| 418 | + var data = hasBody ? this : undefined; |
419 | 419 | Resource[name].call(this, params, data, success, error); |
420 | 420 | }; |
421 | 421 | }); |
|
0 commit comments