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
22
votes
5 answers

angular http: how to call images with custom headers?

In the html view, images are displayed like this: element.image.url points to an url like: /rest_api/img/12345678. This is working fine, images are displayed. Now, I add authentication: Before the user is…
François Romain
  • 13,617
  • 17
  • 89
  • 123
19
votes
3 answers

How to access response headers using $resource in Angular?

I basically call get requests like so: var resource = $resource('/api/v1/categories/:id') resource.get({id: 1}).$promise.then(function(data){ console.log(data) }) This works fine.. but how do I get the response headers?
Nathan
  • 7,627
  • 11
  • 46
  • 80
16
votes
2 answers

Is it possible to use parameterized URL templates with angular $http service

I'm using $resource for my RESTful api's and love the parameterized URL template for example 'api/clients/:clientId' This works great for CRUD operations. Some of my api's however are just reports or read-only end points without the need for the…
hkrauss2
  • 307
  • 2
  • 9
15
votes
2 answers

Difference between .save and $save to resource in angularjs

I've seen code that both calls $save and save to a $resource in angular. What is the difference and when do you use either?
happygilmore
  • 3,008
  • 4
  • 23
  • 37
14
votes
2 answers

Why angular sets undefined to empty ng-model fields

I have simple crud application in Angular (1.2) and Laravel (4.2). To simple crud operations I use efficient Eloquent method: $product->fill(Input::all()); which takes all fields from request payload, but is there a problem when I need to do update…
Karol F
  • 1,556
  • 2
  • 18
  • 33
14
votes
2 answers

How do I remove the default headers just for specific XHR requests in AngularJS?

99% of my ajax calls need a specific "X-API-TOKEN" to authenticate and communicate with my Rails REST API. But I'm also making a call to one thrid party API and I keep getting an error saying "Request header field X-API-TOKEN is not allowed by…
avian
  • 1,693
  • 3
  • 20
  • 30
13
votes
2 answers

Dynamic Resource Headers

I would like to have service providing a resource as in the following code: angular.module('myApp.userService', ['ngResource']) .factory('UserService', function ($resource) { var user = $resource('/api/user', {}, { …
unludo
  • 4,912
  • 7
  • 47
  • 71
12
votes
1 answer

PDF.JS: Render PDF using an ArrayBuffer or Blob instead of URL

I know of a similar question to this one: Pdf.js: rendering a pdf file using a base64 file source instead of url. That question was awesomely answered by Codetoffel but my question is different in that my PDF is retrieved via a RESTful call to my…
witttness
  • 4,984
  • 4
  • 25
  • 24
12
votes
1 answer

AngularJS transformResponse

In angularjs resource, I would like to convert my json data into JS objects //Complex object with inheritance chain function Car(year, make){ this.make = make; this.year = year; } var carResource = $resource("/api/car/id", {id: '@id'}, …
Mr Hyde
  • 3,393
  • 8
  • 36
  • 48
12
votes
1 answer

Angularjs resource query() result array as a property

I like the way the query() method returns an array of resources, which can be saved to the server again. I am trying to use Angular against the Drupal RestWS module, which returns an object with several "meta" properties and a property called list…
mojzis
  • 324
  • 1
  • 2
  • 13
11
votes
2 answers

AngularJS $resource - POST with id param

I have an angularJS $resource: $resource("http://localhost:3000/:id",{ id: '@id' }, { get: { method:'GET', isArray: false }, foo: { method:'POST', url: 'http://localhost:3000/:id/foo', isArray: false …
richwol
  • 1,065
  • 2
  • 11
  • 24
11
votes
4 answers

Using $resource.query, I want to return an object that contains an array of the actual resource

By default, the $resource.query() is set up to expect an array of objects that become $resource objects. To accommodate paging in a nice, restful way, I have my GET /api/widgets endpoint set up to return the following object: { currentPage: 1, …
w.brian
  • 16,296
  • 14
  • 69
  • 118
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
1 answer

What is the AngularJS equivalent to Backbone's Collections?

Is there an equivalent to Backbone's Collection or Ext JS's Store in Angular JS? I'm learning about $resource, but not quite getting this aspect. Controller // This is the "collection" I'm interested in. $scope.foos = []; // Foo is a…
9
votes
2 answers

What is the difference between $promise and $q promises in angular1.x?

I started using promises in angular for resolving my api calls with the following syntax: $scope.module = moduleFactory.get({id: $stateParams.id}) .$promise.then(function(response){ $scope.module = response; } Now, I have…
1
2
3
50 51