angular-resource

Cannot read response from AngularJS $resource DELETE

情到浓时终转凉″ 提交于 2019-12-06 07:49:04
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('MyServicesName', ['ngResource']); MyServices.factory('AAAService', function($resource) { return

AngujarJS server-side pagination grand total items using $resource

被刻印的时光 ゝ 提交于 2019-12-06 07:40:47
I'm trying to implement server-side pagination on an AngujarJS app but haven't figured out how to get the grand total (not the per-request total) items in a given JSON response without having to do an additional request: $scope.books = []; $scope.limit = 3; $scope.offset = 0; $scope.search = function () { Books.query({ q: $scope.query, limit: $scope.limit, offset: $scope.offset }, function (response) { $scope.books = response; } ); }; $scope.previous = function () { if ($scope.offset >= $scope.limit) { $scope.offset = $scope.offset - $scope.limit; $scope.search(); } } $scope.next = function ()

$resource update method behaving strangely

纵然是瞬间 提交于 2019-12-06 03:14:30
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) { return $resource('project/:id',{},{ query: { method: 'GET', isArray: false }, update: { method: 'PUT' }

Change the base URL for a resource

隐身守侯 提交于 2019-12-06 00:05:40
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 resource is appended to the current URL: GET | http://sample-site/friends/1/api/contact but what I really

Angular Resource Encoding URL

微笑、不失礼 提交于 2019-12-05 22:07:46
问题 I have a resource defined as follows: app.factory("DatumItem", function($resource) { return $resource('/data/:id', {id: '@id'}); }); In my view I have: <div ng-click="go('/datum/' + d.to_param)">Test</div> where go() is defined in my controller as: $scope.go = function (params) { $location.path(params); }; For the item in question, d.param is equal to TkZUOWZwcnc9Uldo%0ASzRvd2FiWk But when I call DatumItem.get() with the correct ID, it is changing the id to TkZUOWZwcnc9Uldo%250ASzRvd2FiWk Is

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

冷暖自知 提交于 2019-12-05 21:47:15
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 the server down to the client, it does not build an array of "SimpleResult" objects, but a single

AngularJS $promise is undefined

旧巷老猫 提交于 2019-12-05 20:34:47
I am trying to make an ajax call using $resource and load a datatable upon receiving the data from a server. But when I call a get() then I am getting $promise as undefined. I am using a factory to make the call. Here is my factory : app.factory('getAllUsers', [ '$resource', function($resource) { return $resource('URL', {}, {get : {method : 'GET'}}); }]); And the controller : app.controller('MyController',function($scope,$location,getAllUsers){ console.log("In controller"); getAllUsers.get().$promise.then(function(data) { loadDatatable(data); }); }); ERROR : getAllUsers.get().$promise is

Sending ETag with $resource

☆樱花仙子☆ 提交于 2019-12-05 11:26:41
Using Angular JS's $resource service, is there a way to specify the If-None-Match and ETag headers for the 2nd, 3rd, etc polls of a resource? var SummarySearch = $resource(<<apiurl>>, { }, { get: { method: 'GET', headers: { 'x-header': 'id' } } }); I've gotten this to work for setting a constant header (it's just x-header: id in this case), but I need something that varies per request, based on the ETag I last saw. Update: transformRequest looked promising, but I don't have access to the data that I initiated the request with, or the URL where that data ended up. As far as I can tell I only

angularjs handling $resource $promise errors

隐身守侯 提交于 2019-12-05 03:31:14
问题 Could somebody help me figure out how to return hard-coded data in my AngularJS factory if there is an error connecting to my API. My hard-coded data are located in another factory called "dataFactory". Appreciate the assistance. service.factory("ScheduleFactory", ['$http', '$resource', '$q', 'dataFactory', function($http, $resource, $q, dataFactory) { var objFactory = {}; objFactory.getDaysOfWeek = function(includeWeekends) { var days = []; var API = $resource(restURL + '/daysOfWeek/'); API

Difference between .save and $save to resource in angularjs

一笑奈何 提交于 2019-12-05 00:51:37
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? Best explanation === example : // by writing '{ id: '@id' }' we want the id to be taken from 'id' parameter in request data, hence the '@' sign. Note that this mechanism is available for non-GET RQs only: var Notes = $resource('/notes/:id', { id: '@id' }); var noteId = "my_note1"; // below we specify 'id' explicitly - has to be done for GET RQ: // operations on our note are done inside callback function, just to make sure that the note is resolved: var note = Notes.get({