From feacf608eefa8cc64845a643f7270c9c3a16d1b8 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Wed, 19 Oct 2011 10:47:17 -0700 Subject: fix($resource): to work with $http, $httpBackend services Breaks Disabling $resource caching for the moment. --- src/Resource.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/Resource.js') diff --git a/src/Resource.js b/src/Resource.js index 959561e4..4bec60f9 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -36,8 +36,8 @@ Route.prototype = { } }; -function ResourceFactory(xhr) { - this.xhr = xhr; +function ResourceFactory($http) { + this.$http = $http; } ResourceFactory.DEFAULT_ACTIONS = { @@ -107,11 +107,11 @@ ResourceFactory.prototype = { } var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data)); - self.xhr( - action.method, - route.url(extend({}, extractParams(data), action.params || {}, params)), - data, - function(status, response) { + var future = self.$http({ + method: action.method, + url: route.url(extend({}, extractParams(data), action.params || {}, params)), + data: data + }).on('success', function(response, status) { if (response) { if (action.isArray) { value.length = 0; @@ -123,9 +123,10 @@ ResourceFactory.prototype = { } } (success||noop)(value); - }, - error || action.verifyCache, - action.verifyCache); + }); + + if (error) future.on('error', error); + return value; }; -- cgit v1.2.3