Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngResource): support extending resources #7308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -597,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;
},
Expand Down