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
4
votes
3 answers

Aborting ngResource using a promise object

I've recently learned that ngResource request can be aborted either by specifying a timeout in ms or passing a deferred object. The second solution does not seem to work for me, and I have no idea what I'm doing wrong. I've created a fiddle to…
Jan Vorcak
  • 19,261
  • 14
  • 54
  • 90
4
votes
1 answer

Change the base URL for a resource

I'm using Angular to consume a RESTful API on the same application. I have a $resource setup for the contacts resource at http://sample-site.com/api/contacts This is great and it works, however I need to interact with the basic CRUD of /api/contacts…
Dylan Pierce
  • 4,313
  • 3
  • 35
  • 45
4
votes
2 answers

render 404 page without redirecting in angular js

I am using ui.router & ngResource with AngularJS, & my question is : How do I RENDER 404 without redirecting to it e.g A user typed http://www.example.com/wrong-page-name , he should just be shown the 404 page, and the URL shouldn't change.…
4
votes
0 answers

Getting query parameter in AngularJS Resource transformResponse function

I'm trying to create simple "database" in json file, and service for it with function to get specific item from json parsed array. I'm using sample modified code from angular tutorial: var projectService = angular.module('projectService',…
Marrbacca
  • 137
  • 1
  • 10
4
votes
1 answer

Proper $resource POST parameters to Rails

I'm trying to POST some data to my Rails 4 API. The resource: App.factory 'House', ['$resource', ($resource) -> $resource '/api/v1/houses/:id', { id: '@id' } ] The JSON representation of the resource: newHouse = { "owner_id": "30", "name":…
Nuno Silva
  • 728
  • 11
  • 27
4
votes
1 answer

AngularJS - Controller resource call not passing parameters to service factory?

In AngularJS, I'm trying to pass a parameter in a controller call to a service factory. However, I can't seem to get the parameter passed. The function always passes what I set to be the default in the service. And if I don't include the default, it…
golmschenk
  • 11,736
  • 20
  • 78
  • 137
4
votes
1 answer

How to handle 3-level deep nested resources with ngResource?

I am working on my first AngularJS application in order to learn the framework. I am currently hiting a wall finding the idiomatic way to handle nested resources. I have areas containing buildings containing flats. One flat is only inside one…
Thomas
  • 1,360
  • 1
  • 9
  • 15
4
votes
1 answer

how to build angular $resource POST request to server?

I can't catch request on ASP.NET MVC project on server side controller from AngularJS: var appDirective = angular.module('app.directive', []); var xmplService = angular.module('app.service', ['ngResource']); var appFilter =…
Darien Fawkes
  • 3,023
  • 7
  • 24
  • 35
4
votes
1 answer

Downloading an XML file using angularJs resource

I'm trying to use angularJs resource to download a file from a server but it dosen't work. my code is as following: // service angular.module("someModule") .factory('generate', ['$resource', '$rootScope', function ($resource, $rootScope) { return…
Rivi
  • 791
  • 3
  • 15
  • 23
4
votes
2 answers

How to cancel an ongoing REST-call using Angular's $resource?

I've been looking over and over for an example on how to cancel an ongoing REST-call using Angular's $resource. I haven't found any solution yet, but from the Angular documentation I got the impression that it should be possible. From the…
jstensen
  • 157
  • 1
  • 2
  • 9
4
votes
1 answer

Angularjs is changing URL back to original causing issue

My application is based on Single page model. I am using JQuery History object to change the URL so that if user refresh the application then I can retain the position of application when user refreshed the browser. It was working good however…
joy
  • 3,669
  • 7
  • 38
  • 73
4
votes
1 answer

how to set timeout in ngResource query method on runtime

I have a service holding all my API endpoint connectors. Those endpoint connectors are ngResource objects. In some of them I override default methods, such as get or query for example to add responseTransformers. I'd like to be able to set timeout…
renczus
  • 170
  • 7
4
votes
3 answers

AngularJS $resource calls the wrong API URL when using method:POST

Not the easiest issue to put into a title. Anyhow, my app is built on nodejs/expressjsand has an API set up for the url: EDIT: The current code I'm using is: $scope.updateProduct = $resource('/api/updateProduct/:product/:param/:value',{},{ query:…
JVG
  • 20,198
  • 47
  • 132
  • 210
4
votes
1 answer

ServiceStack: use attribute in DTO to set response header and response body

I'm using servicestack with an AngularJS Resource module. The problem is that when I call the query() method of my service to request a paginated list, I want to send a custom response header with the total number of rows. I would like the http…
4
votes
2 answers

Angular JS Fails After Upgrade from 1.1.0 to 1.1.1

When I upgrade the the ng-repeat takes extraordinarily long to load and tries to display MORE content boxes without the content that is being served by $resource. I have narrowed the problem down to the update between 1.1.0 and 1.1.1. I looked…