Skip to content

Commit feacf60

Browse files
vojtajinaIgorMinar
authored andcommitted
fix($resource): to work with $http, $httpBackend services
Breaks Disabling $resource caching for the moment.
1 parent fe633dd commit feacf60

3 files changed

Lines changed: 141 additions & 146 deletions

File tree

src/Resource.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Route.prototype = {
3636
}
3737
};
3838

39-
function ResourceFactory(xhr) {
40-
this.xhr = xhr;
39+
function ResourceFactory($http) {
40+
this.$http = $http;
4141
}
4242

4343
ResourceFactory.DEFAULT_ACTIONS = {
@@ -107,11 +107,11 @@ ResourceFactory.prototype = {
107107
}
108108

109109
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
110-
self.xhr(
111-
action.method,
112-
route.url(extend({}, extractParams(data), action.params || {}, params)),
113-
data,
114-
function(status, response) {
110+
var future = self.$http({
111+
method: action.method,
112+
url: route.url(extend({}, extractParams(data), action.params || {}, params)),
113+
data: data
114+
}).on('success', function(response, status) {
115115
if (response) {
116116
if (action.isArray) {
117117
value.length = 0;
@@ -123,9 +123,10 @@ ResourceFactory.prototype = {
123123
}
124124
}
125125
(success||noop)(value);
126-
},
127-
error || action.verifyCache,
128-
action.verifyCache);
126+
});
127+
128+
if (error) future.on('error', error);
129+
129130
return value;
130131
};
131132

src/service/resource.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
/**
44
* @ngdoc object
55
* @name angular.module.ng.$resource
6-
* @requires $xhr.cache
6+
* @requires $http
77
*
88
* @description
99
* A factory which creates a resource object that lets you interact with
1010
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
1111
*
1212
* The returned resource object has action methods which provide high-level behaviors without
13-
* the need to interact with the low level {@link angular.module.ng.$xhr $xhr} service or
14-
* raw XMLHttpRequest.
13+
* the need to interact with the low level {@link angular.module.ng.$http $http} service.
1514
*
1615
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
1716
* `/user/:username`.
@@ -57,7 +56,7 @@
5756
* 'remove': {method:'DELETE'},
5857
* 'delete': {method:'DELETE'} };
5958
*
60-
* Calling these methods invoke an {@link angular.module.ng.$xhr} with the specified http method,
59+
* Calling these methods invoke an {@link angular.module.ng.$http} with the specified http method,
6160
* destination and parameters. When the data is returned from the server then the object is an
6261
* instance of the resource class `save`, `remove` and `delete` actions are available on it as
6362
* methods with the `$` prefix. This allows you to easily perform CRUD operations (create, read,
@@ -128,7 +127,7 @@
128127
* The object returned from this function execution is a resource "class" which has "static" method
129128
* for each action in the definition.
130129
*
131-
* Calling these methods invoke `$xhr` on the `url` template with the given `method` and `params`.
130+
* Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
132131
* When the data is returned from the server then the object is an instance of the resource type and
133132
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
134133
* operations (create, read, update, delete) on server-side data.
@@ -201,8 +200,8 @@
201200
</doc:example>
202201
*/
203202
function $ResourceProvider() {
204-
this.$get = ['$xhr.cache', function($xhr){
205-
var resource = new ResourceFactory($xhr);
203+
this.$get = ['$http', function($http) {
204+
var resource = new ResourceFactory($http);
206205
return bind(resource, resource.route);
207206
}];
208207
}

0 commit comments

Comments
 (0)