aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Resource.js13
-rw-r--r--src/service/resource.js10
2 files changed, 14 insertions, 9 deletions
diff --git a/src/Resource.js b/src/Resource.js
index f4440e00..3b4a6db1 100644
--- a/src/Resource.js
+++ b/src/Resource.js
@@ -107,23 +107,24 @@ ResourceFactory.prototype = {
}
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
- var future = self.$http({
+ self.$http({
method: action.method,
url: route.url(extend({}, extractParams(data), action.params || {}, params)),
data: data
}).then(function(response) {
- response = response.data;
- if (response) {
+ var data = response.data;
+
+ if (data) {
if (action.isArray) {
value.length = 0;
- forEach(response, function(item) {
+ forEach(data, function(item) {
value.push(new Resource(item));
});
} else {
- copy(response, value);
+ copy(data, value);
}
}
- (success||noop)(value);
+ (success||noop)(value, response.headers);
}, error);
return value;
diff --git a/src/service/resource.js b/src/service/resource.js
index 8fe27f1b..bee5af47 100644
--- a/src/service/resource.js
+++ b/src/service/resource.js
@@ -141,13 +141,17 @@
</pre>
*
* It's worth noting that the success 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:
+ * in the response that came from the server as well as $http header getter function, so one
+ * could rewrite the above example and get access to http headers as:
*
<pre>
var User = $resource('/user/:userId', {userId:'@id'});
- User.get({userId:123}, function(u){
+ User.get({userId:123}, function(u, getResponseHeaders){
u.abc = true;
- u.$save();
+ u.$save(function(u, putResponseHeaders) {
+ //u => saved user object
+ //putResponseHeaders => $http header getter
+ });
});
</pre>