From c609181699df21d0256748323d121501fa80f8f8 Mon Sep 17 00:00:00 2001 From: yohai Date: Tue, 29 Apr 2014 15:47:40 +0300 Subject: [PATCH 1/2] fix(ngResource): change to make resource support instance's array action --- src/ngResource/resource.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index ce3468794094..c98997a15e35 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -536,8 +536,14 @@ angular.module('ngResource', ['ng']). } /* jshint +W086 */ /* (purposefully fall through case statements) */ - var isInstanceCall = this instanceof Resource; - var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data)); + var isInstanceCall = this instanceof Resource, value; + + if (action.isArray) { + value = []; + } else { + value = isInstanceCall ? data : new Resource(data); + } + var httpConfig = {}; var responseInterceptor = action.interceptor && action.interceptor.response || defaultResponseInterceptor; From c14cfce781da71775ca8faafc66a40944ac5406f Mon Sep 17 00:00:00 2001 From: yohai Date: Wed, 30 Apr 2014 11:14:13 +0300 Subject: [PATCH 2/2] feat(ngResource): change that makes it possible to extend resources call ngResource's response interceptor with the resource's instance as the context to give the user the abillity to reference it from within the interceptor function and set the response data on it Closes #4565 --- src/ngResource/resource.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index c98997a15e35..5114c1efe0ee 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -603,6 +603,9 @@ angular.module('ngResource', ['ng']). promise = promise.then( function (response) { var value = responseInterceptor(response); + if(action.saveAs){ + data[action.saveAs] = value; + } (success || noop)(value, response.headers); return value; },