Questions tagged [angularjs-resource]

The ngResource module provides interaction support with RESTful services via the $resource service.

From Angularjs documentation:

The ngResource module provides interaction support with RESTful services via the $resource service.

$resource

A factory which creates a resource object that lets you interact with RESTful server-side data sources.

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;
}]);
277 questions
295
votes
3 answers

'Best' practice for restful POST response

So nothing new here I am just trying to get some clarification and cannot seem to find any in other posts. I am creating a new resource restulfully, say: /books (POST) with a body: { title: 'The Lion, the Witch and the Wardrobe', author: 'C. S.…
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
96
votes
3 answers

How to refresh / invalidate $resource cache in AngularJS

I have a simple User $resource that uses the default $http cache implementation like so: factory('User', function($resource){ return $resource(endpoint + '/user/current/:projectId', {}, {get: { cache: true, …
Alexandre Bulté
  • 1,402
  • 1
  • 12
  • 14
37
votes
4 answers

Angular - extending $resource subobject with custom methods

In most cases the result of .query() method is an array, which can be easily extended with some methods (business logics) with the following (factory) code: var Data = $resource('http://..'); Data.prototype.foo = function() {return…
migajek
  • 8,524
  • 15
  • 77
  • 116
21
votes
2 answers

How do I not send url template parameters with request body in angular?

Suppose I have a resource set up like this: resource = $resource( "http://foo.com/service/:type/:id", {}, {save: {method:'PUT', params: {type:'@type', id: '@id'}}} ); resource.save({type:'user', id:14, name:'Bob Dole'}); Is there any…
Greg Michalec
  • 849
  • 3
  • 10
  • 17
21
votes
3 answers

add a custom function on angular $resource

I have an angular resource that goes something like this app.factory('User', function ($resource) { return $resource( '/api/user/:listCtrl:id/:docCtrl/', { id: '@id', listCtrl: '@listCtrl', docCtrl:…
Yousuf Jawwad
  • 3,037
  • 7
  • 33
  • 60
18
votes
3 answers

Invalidate $resource Cache After Post Request

I am using $resource and caching the results of get requests. My problem is that, after post requests, the cache is not being invalidated. Here is the return value from the service: return $resource('http://url.com/api/url/:id', {}, { 'query' : { …
inperspective
  • 1,854
  • 1
  • 19
  • 21
15
votes
5 answers

How can I extend the constructor of an AngularJS resource ($resource)?

I have a model, defined using $resource, that I am successfully loading. Each loaded instance is, as promised, an instance of the class I defined. (The example below is from the Angular docs. In it, User.get results in an object that is an…
Alan H.
  • 16,219
  • 17
  • 80
  • 113
14
votes
4 answers

Protractor times out waiting for sync with page when using $resource

I'm testing Protractor with a small AngularJS app. This is the test: describe('Testing Protractor', function() { var draftList; it('should count the number of drafts', function() { browser.get('#/'); draftList =…
Joseph S.
  • 475
  • 1
  • 6
  • 11
14
votes
1 answer

Angular 1.0.8 $resource with multiple optional get parameters

My Student ulr looks like this: var Student = $resource('/app/student/:studentid:courseId', {studentid:'@id',courseId:'@cid'} ); When I call it without parameters I would like the url be /app/student/ (works) var names=Student.query( …
HMR
  • 37,593
  • 24
  • 91
  • 160
13
votes
2 answers

How do I get a null response from a $resource?

How do I get a null response from a $resource? I am running this: angular.module("services").factory('Member', function($resource) { var Member = $resource('/api/v1/member.json'); Member.current = Member.get(); return Member; }); But the…
Petah
  • 45,477
  • 28
  • 157
  • 213
12
votes
3 answers

Get response header in then() function of a ngResource object's $promise property after resource resolved?

I'm willing to retrieve the response header of a resource request, cause I've put pagination information and something else in it rather than the response body, to make the REST api clear. Though we can get it from the success / error callback like…
Uice Stone
  • 137
  • 1
  • 1
  • 7
12
votes
3 answers

Angular Resource - how to check if a resource instance has any unsaved changes?

I want to be able to tell whether an $resource instance has been modified by the user - that is, whether its current state is different than what has been initially loaded from the server && has not yet been $saved. How can I achieve that?
Kuba Orlik
  • 3,360
  • 6
  • 34
  • 49
11
votes
2 answers

AngularJS: transform response in $resource using a custom service

I am trying to decorate the returned data from a angular $resource with data from a custom service. My code is: angular.module('yoApp') .service('ServerStatus', ['$resource', 'ServerConfig', function($resource, ServerConfig) { var mixinConfig…
Maddin
  • 957
  • 1
  • 11
  • 21
10
votes
3 answers

Load directive after AJAX call

I have build a directive for pagination that takes two arguments; the current page and the total number of pages. The issue is that I will only know the value of numberOfPages…
Erik Nijland
  • 1,181
  • 2
  • 9
  • 24
10
votes
3 answers

AngularJS and complex JSON returned by django tastypie

I have few resources written on AngularJS that access a Tastypie API. Everything works fine, except for a detail: tastypie always encapsulate the actual result inside a objects attribute on a JSON, example: /api/v1/reminder/: { meta: { …
Marcio Cruz
  • 2,012
  • 1
  • 23
  • 30
1
2 3
18 19