From f6ecf9a3c9090593faf5fa50586c99a56b51c776 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 20 Nov 2013 16:45:39 -0800 Subject: fix($resource): Always return a resource instance when calling class methods on resources. Previously, calling `MyResource.save(myResourceInstance)`returned a promise, in contrast to the docs for `$resource`. However, calling `MyResource.save({name: 'Tobias"})`already correctly returned a resource instance. Fixes #4545. Closes #5061. --- src/ngResource/resource.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ngResource') diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index d11a4d60..e2499864 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -439,7 +439,7 @@ angular.module('ngResource', ['ng']). } /* jshint +W086 */ /* (purposefully fall through case statements) */ - var isInstanceCall = data instanceof Resource; + var isInstanceCall = this instanceof Resource; var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data)); var httpConfig = {}; var responseInterceptor = action.interceptor && action.interceptor.response || @@ -522,7 +522,7 @@ angular.module('ngResource', ['ng']). if (isFunction(params)) { error = success; success = params; params = {}; } - var result = Resource[name](params, this, success, error); + var result = Resource[name].call(this, params, this, success, error); return result.$promise || result; }; }); -- cgit v1.2.3