aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVojta Jina2011-10-19 10:47:17 -0700
committerIgor Minar2011-11-30 11:17:22 -0500
commitfeacf608eefa8cc64845a643f7270c9c3a16d1b8 (patch)
tree43b13081c41f17b7994577c6cb02e6216f5c5b30 /src
parentfe633dd0cf3d52f84ce73f486bcbd4e1d3058857 (diff)
downloadangular.js-feacf608eefa8cc64845a643f7270c9c3a16d1b8.tar.bz2
fix($resource): to work with $http, $httpBackend services
Breaks Disabling $resource caching for the moment.
Diffstat (limited to 'src')
-rw-r--r--src/Resource.js21
-rw-r--r--src/service/resource.js13
2 files changed, 17 insertions, 17 deletions
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;
};
diff --git a/src/service/resource.js b/src/service/resource.js
index 2082b9ed..8fe27f1b 100644
--- a/src/service/resource.js
+++ b/src/service/resource.js
@@ -3,15 +3,14 @@
/**
* @ngdoc object
* @name angular.module.ng.$resource
- * @requires $xhr.cache
+ * @requires $http
*
* @description
* A factory which creates a resource object that lets you interact with
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
*
* The returned resource object has action methods which provide high-level behaviors without
- * the need to interact with the low level {@link angular.module.ng.$xhr $xhr} service or
- * raw XMLHttpRequest.
+ * the need to interact with the low level {@link angular.module.ng.$http $http} service.
*
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
* `/user/:username`.
@@ -57,7 +56,7 @@
* 'remove': {method:'DELETE'},
* 'delete': {method:'DELETE'} };
*
- * Calling these methods invoke an {@link angular.module.ng.$xhr} with the specified http method,
+ * Calling these methods invoke an {@link angular.module.ng.$http} with the specified http method,
* destination and parameters. When the data is returned from the server then the object is an
* instance of the resource class `save`, `remove` and `delete` actions are available on it as
* methods with the `$` prefix. This allows you to easily perform CRUD operations (create, read,
@@ -128,7 +127,7 @@
* The object returned from this function execution is a resource "class" which has "static" method
* for each action in the definition.
*
- * Calling these methods invoke `$xhr` on the `url` template with the given `method` and `params`.
+ * Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
* When the data is returned from the server then the object is an instance of the resource type and
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
* operations (create, read, update, delete) on server-side data.
@@ -201,8 +200,8 @@
</doc:example>
*/
function $ResourceProvider() {
- this.$get = ['$xhr.cache', function($xhr){
- var resource = new ResourceFactory($xhr);
+ this.$get = ['$http', function($http) {
+ var resource = new ResourceFactory($http);
return bind(resource, resource.route);
}];
}