angular-resource

Error status codes are not being caught

ぐ巨炮叔叔 提交于 2019-12-23 13:06:56
问题 I am trying to catch angular resource's HTTP error status code (!=200). My Service, where I have resources defined: (apiService.js) .factory('ApiService', function($resource, $http, localStorageService, CONFIG) { var base_api_url = api_url = CONFIG.api_url, api_version_prefix = CONFIG.api_version_prefix; return { userDevices: $resource(api_url+'/requestRegistration/userDevices/:action', {}, { registerDevice: { method: 'POST', params: { action: '' } }, verify: { method: 'POST', params: {

Properly wrap new domain object instance with $resource

五迷三道 提交于 2019-12-23 03:05:21
问题 As a follow up to $resource to return array of [OO] objects how to properly wrap new domain object instances from $resource app.factory('NoteResource', ['$resource', function($resource) { var res = $resource('http://okigan.apiary.io/notes/:id', null, ...); res.newInstance = function() { return angular.extend(new Note(), res); }; } NoteResource.newInstance() shall return object with standard $save/$update methods. Best to modify the plunker and watch traffic then "New note" button shall work

Unit-testing ngResource $save

天涯浪子 提交于 2019-12-23 02:43:10
问题 I have a resource which wraps a RESTful API. I use that resource from my controller to create new objects and save them, similar to this snippet from the Angular docs: var newCard = new CreditCard({number:'0123'}); newCard.name = "Mike Smith"; newCard.$save(); When writing a unit test in Jasmine, I get the following error when the $save call is executed: "Cannot read property '$promise' of undefined". What's the best approach to testing the method in my controller which contains the above

Cannot read response from AngularJS $resource DELETE

我的梦境 提交于 2019-12-22 12:29:12
问题 I am trying to use AngularJS $resource to DELETE data from my server. However, when I write the result to console, I do not see the data. However, when I go to "Network" in Chrome's console, I see the DELETE in the Name Path left column. When I click on the "info, I see five tabs on the right panel. Under the Preview and Response tabs, I see the correct data. I just don't know how to see or retrieve that in my Javascript. Here is the javascript service code: var MyServices = angular.module(

Change the base URL for a resource

こ雲淡風輕ζ 提交于 2019-12-22 11:14:24
问题 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 on different pages of the application. For example, I need to interact with contacts again at another page on web app hosted at http://sample-site/friends/{friend-id} . However when I try to use my contact resource on that page, the url to the

Hot to return a pure array of objects from AppEngine endpoint?

房东的猫 提交于 2019-12-22 10:39:03
问题 I am doing AppEngine endpoints for a RESTFul backend in AppEngine. I use AngujarJS on the client side, managing server data with ngResource. My issue: I am not able to return a pure array from AppEngine Endpoint. I tried this: @ApiMethod( name = "mpscorerapi.getAllResults", path = "/tournament/{tournamentId}/result/" httpMethod = HttpMethod.GET ) public List<SimpleResult> getAllResults(@Named("tournamentId") Long tournamentId) throws NotFoundException { ... } Although this gets the data from

$resource update method behaving strangely

眉间皱痕 提交于 2019-12-22 10:36:18
问题 Reading/Creating/Deleting is all working fine for a particular $resource, however Editing is not going so well. In my app config I have: $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; This is working fine for both POST/PUT, maybe it's worth mentioning. My $resource definition looks like: app.factory('Project', function($resource) {

Aborting ngResource using a promise object

拟墨画扇 提交于 2019-12-19 21:50:40
问题 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 demonstrate the problem http://jsfiddle.net/HB7LU/10977/ var myApp = angular.module('myApp',['ngResource']); myApp.factory('myResource', function($resource) { return { getResource: function (aborter) { var resource = $resource( 'http://api

AngularJS transformResponse

﹥>﹥吖頭↗ 提交于 2019-12-18 19:17:06
问题 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

How to handle pagination and count with angularjs resources?

谁说胖子不能爱 提交于 2019-12-18 10:23:11
问题 I have to build an angularjs client for an API outputting JSON like this: { "count": 10, "next": null, "previous": "http://site.tld/api/items/?start=4" "results": [ { "url": "http://site.tld/api/items/1.json", "title": "test", "description": "", "user": "http://site.tld/api/users/4.json", "creation_datetime": "2013-05-08T14:31:43.428" }, { "url": "http://site.tld/api/items/2.json", "title": "test2", "description": "", "user": "http://site.tld/api/users/1.json", "creation_datetime": "2013-05