angular-resource

Prevent ngResource from requiring a returned item on $save

牧云@^-^@ 提交于 2019-12-02 15:43:18
问题 It seems that when I $save or use a custom $update (put or post) method on my resource that it expects the newly posted document to be returned. I don't want to return anything from my save/post ops but an ok/200/error type of statement but doing so causes the item to be blank as soon as saved. var item = Things.get({ id: $route.current.params.id }, function() { console.log(item); // Item is ok }); var item = Things.get({ id: $route.current.params.id }, function() { console.log(item); // Item

Prevent ngResource from requiring a returned item on $save

落花浮王杯 提交于 2019-12-02 09:37:46
It seems that when I $save or use a custom $update (put or post) method on my resource that it expects the newly posted document to be returned. I don't want to return anything from my save/post ops but an ok/200/error type of statement but doing so causes the item to be blank as soon as saved. var item = Things.get({ id: $route.current.params.id }, function() { console.log(item); // Item is ok }); var item = Things.get({ id: $route.current.params.id }, function() { console.log(item); // Item is blank (because server returned just 'ok') item.$save(); }); When you do a $save() there will be a

render 404 page without redirecting in angular js

旧时模样 提交于 2019-12-01 04:21:39
问题 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. Currently this is how I did it but it redirects angular.module('app') .run(['$rootScope', '$state', function($rootScope, $state) { $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { if(error.status ===

AngularJS transformResponse

送分小仙女□ 提交于 2019-11-30 18:01:20
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'}, { get: { method: 'GET', transformResponse: function(data, headersGetter){ return new Car(data.make, data.year); } } } ) However this does not seem to be happening What I am getting back is a $resource object meaning that the properties make and year are set correctly, however the prototype of the returned object points to $resource Is there a way where I can map

Angularjs resource query() result array as a property

泄露秘密 提交于 2019-11-30 06:53:35
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 where the actual data are stored. Is there please a way of telling the resource to take that array instead ? Example : GET author.json returns : first: "http://dgh/author?page=0" last: "http://dgh/author?page=0" list: [{id:1, type:author, uid:{uri:http://dgh/user/1, id:1, resource:user}, created:1367770006,…},…] self: "http://dgh/author" With the

How to cancel $resource requests

元气小坏坏 提交于 2019-11-30 06:19:19
问题 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 possible. In the meantime, I'm just trying to cancel all pending requests, and then resetting the timeout promise to allow new requests. The issue seems to be that the $resource configuration only allows a single, static promise for the timeout value.

Make angularjs $resource return array of [OO] objects

怎甘沉沦 提交于 2019-11-29 11:03:25
How to make angularjs $resource return an array of objects derived/prototyped from specified domain object? Here is an example on http://plnkr.co/edit/AVLQItPIfoLwsgDzoBdK?p=preview that processes a set of Note s objects. app.controller('MainCtrl', function($scope, NoteResource) { $scope.name = 'World'; $scope.notes = NoteResource.query(); $scope.spellCheckAllNotes = function() { angular.forEach($scope.notes, function(note) { note.spellCheck(); }); } }); The issue is that $resource returns array of Resource s and not an array of Note s with Resource methods added to prototypes. [solution shall

Angularjs resource query() result array as a property

让人想犯罪 __ 提交于 2019-11-29 07:30:36
问题 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 where the actual data are stored. Is there please a way of telling the resource to take that array instead ? Example : GET author.json returns : first: "http://dgh/author?page=0" last: "http://dgh/author?page=0" list: [{id:1, type:author, uid:{uri

Angular $resource does not parse correctly an integer response

孤者浪人 提交于 2019-11-29 04:31:30
I am using the Angular $resource to make requests to my controllers, implemented on a Spring application. When the controller returns just an Integer value, $resource parse it bad. Inspecting it with Firebug I get something like: Resource { 0="1", 1="9", 2="1", more...} where 191 is just the intger value the server returns. No trouble with others complex object (parsed in JSON by the server). Suggestions? Thanks FB I know this is a little old, but I just ran into a similar problem and someone pointed me in the right direction. If your server is sending back a JSON encoded resonse, but you only

Send Request Body on $resource

空扰寡人 提交于 2019-11-28 18:36:26
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 for $resource . action – {string} – The name of action. This name becomes the name of the method on your resource object. method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP params – {object=} – Optional set of pre-bound parameters for this action. isArray – {boolean=} – If true then the returned object