Questions tagged [angular-resource]

An angularjs factory which creates a resource object that lets you interact with RESTful 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 $http service.

Requires the ngResource module to be installed.

By default, trailing slashes will be stripped from the calculated URLs, which can pose problems with server backends that do not expect that behavior. This can be disabled by configuring the $resourceProvider like this:

app.config(['$resourceProvider', function($resourceProvider) {
  // Don't strip trailing slashes from calculated URLs
  $resourceProvider.defaults.stripTrailingSlashes = false;
}]);

$resource docs

756 questions
97
votes
3 answers

How to handle $resource service errors in AngularJS

I am making requests to my API and I am using AngularJS $resource module. It's different from $http so I don't know how to handle my errors. My service: var appServices = angular.module('app.services',…
valkirilov
  • 1,823
  • 3
  • 20
  • 26
76
votes
4 answers

AngularJS resource promise

I've got a simple controller that use $resource : var Regions = $resource('mocks/regions.json'); $scope.regions = Regions.query(); I'm using this controller in a directive (in the link function) var regions = scope.regions; But regions is…
Thomas Pons
  • 7,709
  • 3
  • 37
  • 55
58
votes
1 answer

AngularJS Automatically Syncing Data between Server and Client

There's something in the AngularJS docs that I can't seem to find or maybe I'm just missing. I'm creating a web app with NodeJS and Express in the back-end and I'm trying to understand how it can interact with Angular in the front end. In…
vilijou
  • 704
  • 1
  • 6
  • 9
55
votes
3 answers

AngularJS: Upload files using $resource (solution)

I'm using AngularJS to interact with a RESTful webservice, using $resource to abstract the various entities exposed. Some of this entities are images, so I need to be able to use the save action of $resource "object" to send both binary data and…
Gian Marco Toso
  • 11,676
  • 5
  • 29
  • 38
45
votes
1 answer

AngularJS: Creating multiple factories for every endpoint?

following some examples, it appears that we can inject a factory which would contain an endpoint for a rest service like so services.factory('Recipe', ['$resource', function($resource) { return $resource('/recipes/:id', {id:…
Martin
  • 23,844
  • 55
  • 201
  • 327
40
votes
1 answer

Difference between delete and remove method in $resource?

What is the difference between delete and remove methods? Both of them use DELETE method of HTTP. I couldn't find any reasonable information.
Paul
  • 25,812
  • 38
  • 124
  • 247
38
votes
2 answers

Testing $resource services in AngularJS

I am trying to begin writing unit tests for my angular application and hit a stopping block pretty quick as I am unsure of how exactly to mock my service in a testable way. Is there a way to mock the REST call otherwise it would seem like I need to…
Brian
  • 2,294
  • 6
  • 30
  • 51
37
votes
2 answers

Send Request Body on $resource

I take a look on Angular API for $resource and I didn't find some way to send a Request Body to a RESTful service. I know this is possible using $http approach, like here, so, is it also possible to do using $resource? Apparently this is the options…
Deividi Cavarzan
  • 10,034
  • 13
  • 66
  • 80
30
votes
0 answers

Comparison of Restangular vs. JSData (formerly Angular-data)

One of the things about Angular that's both a feature and a point of complexity, is that it's not very opinionated about how to interact with a RESTful API. I know about $resource, Restangular, and various ideas you can find on rolling your own. In…
jmq
  • 2,359
  • 18
  • 32
30
votes
1 answer

AngularJS $resource passes id as query parameter instead in url

I need to GET data from a rest API, with the product id part of the url (and not as query parameter). The factory: .factory('Products', ['$resource', function($resource) { return $resource('products/:productId', { productId:…
orszaczky
  • 13,301
  • 8
  • 47
  • 54
29
votes
2 answers

Rails duplicated the parameters inside the resource

I am using the Angular Resource and I don't understand why Rails duplicated the parameters and put it inside the resource name. I just need to understand why this is happening. // post data {"title":"asdsad"} // rails parameters Parameters:…
Yordis Prieto Lazo
  • 729
  • 12
  • 24
29
votes
1 answer

AngularJS - Using $resource.query with params object

I'm trying to pick up angular.js and working on figuring out some of the things that are a bit less documented. Consider this - I have a search method on the server that accepts query params and returns a collection of search results, and responds…
sa125
  • 28,121
  • 38
  • 111
  • 153
28
votes
4 answers

How to handle pagination and count with angularjs resources?

I have to build an angularjs client for an API outputting JSON like this: { "count": 10, "next": null, "previous": "http://site.tld/api/items/?start=4" "results": [ { "url": "http://site.tld/api/items/1.json", "title":…
Bite code
  • 578,959
  • 113
  • 301
  • 329
27
votes
6 answers

How to cancel $resource requests

I'm trying to figure out how to use the timeout property of a $resource to dynamically cancel pending requests. Ideally, I'd like to just be able to cancel requests with certain attributes (based on the params sent), but it seems this may not be…
Greg Michalec
  • 849
  • 3
  • 10
  • 17
25
votes
3 answers

What is a clean way to send a body with DELETE request?

I need to send a request body with my DELETE requests using $resource The only way I could see to do this was to change: https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js From var hasBody = action.method == 'POST' ||…
paullth
  • 1,731
  • 2
  • 15
  • 19
1
2 3
50 51