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
2
votes
2 answers

Cant Access data out of $resource.query() in Angular JS

I am using query function of $resource as follows resource.query(function(details){ $scope.details=details; console.log($scope.details); }) console.log($scope.details); In above code first console.log is printing the exact data. but second…
Gaurav Bhusare
  • 195
  • 1
  • 17
2
votes
1 answer

Should an angularjs $resource be wrapped in a factory? Why not service?

why a $resource should be used by .factory? and why .service is a wrong way? e.g. app.factory('Notes', ['$resource', function($resource) { return $resource('/notes/:id', null, { 'update': { method:'PUT' } }); }]); why is it…
2
votes
2 answers

Angular $resource then not returning data

I have this simple app witha factory and a controller: angular.module('AppName', ['ngResource']) .factory('apiData', ['$resource', function ($resource) { var apiRequest = $resource("https://live.reddcoin.com/api/addr/:address/balance"); …
neptune
  • 1,211
  • 2
  • 19
  • 32
2
votes
0 answers

Can I access Route.setUrlParams method defined in angularjs/ngResource/resource.js through a decent hack?

This is a very specific question. All I would like to do is to obtain the URL used by the $resource when it makes calls. For example var r = $resource('res/:res_id', {res_id: 2}); The reason is that I want access the URL sometimes from an object…
Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96
2
votes
1 answer

Send complex types with Angular Resource to ServiceStack

So I want to send some complex types with Angular Resource to my ServiceStack backend. In the frontend it looks like this: MyResource.get({ Data: { countries: ["DE","CH","AT"] } SomeMoreParams: "hi" }); Here's my…
user2657874
2
votes
0 answers

Data Store using $resource, $cacheFactory with errorHandlingDirective

Learning AngularJS and trying to create a SPA with a data store for a REST server. To reduce the traffic as much as possible, I want to cache the data whenever possible. In the case of an error response from the server, I would like to handle in…
2
votes
1 answer

$resource service .success is not a function

I want to implement the login method with AngularJS, Node and MongoDB. I have built a Restful API where I send the request. When I try to execute the GET request this error appears at the console TypeError: UserService.logIn(...).success is not a…
Antifa
  • 377
  • 1
  • 4
  • 14
2
votes
1 answer

How to use angular's $resource with TypeScript and d.ts

With this TypeScript (based on some online course): interface IProduct { productName: string } interface IProductResource extends ng.resource.IResource { } interface IDataAccessService { getProductService():…
dragonfly
  • 17,407
  • 30
  • 110
  • 219
2
votes
3 answers

using ngResource with webpack

Good morning everyone, I recently started using webpack on a new angular project. I really like it, very easy to use. I just have one problem, for now. I'm trying to import ngResource to use on one of my modules, but not way I try works. I'm using…
Chiptus
  • 949
  • 9
  • 25
2
votes
1 answer

HTTP post method doesn't work in IE11

I am trying to send a HTTP Post method from IE11 but it's not working. When Fiddler is open it detects a protocol violation: "Content-Length mismatch : Request header indicates X bytes, but client sent 0 bytes". It's working on Chrome, and I can't…
2
votes
2 answers

Ajax call within a loop using $resource

I'm in difficulty doing this operation correctly. I have an Order and for every item I have to get the data from the API, what I'm doing is this: if ($scope.order.order_items.length > 0) { var itemArray = []; for (var i = 0; i <…
Ayeye Brazo
  • 3,316
  • 7
  • 34
  • 67
2
votes
1 answer

Resolve Angular resource promise

I'm running into issues attempting to access the data returned through resource. It appears I am not resolving the promise before accessing the data as my data includes a $promise object and resolved property. Here is my…
MattDionis
  • 3,534
  • 10
  • 51
  • 105
2
votes
1 answer

Get the response using ngResource

I created a factory where I have a method forming the object 'create' and the controller causes through submit REST command. Now I would like a response data because the console I can see that the request was successful. How to do it ? How to get…
user4406224
2
votes
0 answers

Angular $resource action return $resource of different class

So I have a services.js that looks something like this. .factory('User', function($resource) { return $resource('/api/users/:id/', {'id': '@id'}, { groups: { method: 'GET', url: '/api/users/:id/groups', isArray: true …
John Kelly
  • 73
  • 8
2
votes
1 answer

Sorting an array that is the result of a $resource call in AngularJS

I'm trying to get the results of an API call and save it to $scope.segments, so that later I can sort the array using $scope.segments.sort() However, since $scope.segments = SegmentsService.getSegments(jobId); does an async call, $scope.segments is…
Rodrigo Galindez
  • 129
  • 1
  • 2
  • 12