angularjs-resource

How to pass body payload to angular $resource DELETE call

限于喜欢 提交于 2019-12-09 13:42:30
问题 I have standard angular $resource configured as such angular.module('client.resources') .factory('ProjectSubjectResource',['$resource', function ($resource) { release: { method: 'DELETE', isArray: false } }); }]); and I am calling this method as ProjectSubjectResource.release({projectId: projectId, subjectId: 0},{ subjectIds: subjectIdArray}) where subjectIdArray is array of objects: [{subject1: 213123}, {subject2: 3131}] However, body of request does not contain that array. I suspect that

Load directive after AJAX call

家住魔仙堡 提交于 2019-12-08 15:42:12
问题 I have build a directive for pagination that takes two arguments; the current page and the total number of pages. <pagination page="page" number-of-pages="numberOfPages"></pagination> The issue is that I will only know the value of numberOfPages after an AJAX call (through ng-resource). But my directive is already rendered before that the AJAX call is done. app.controller('MyController', function ($scope, $routeParams) { $scope.page = +$routeParams.page || 1, $scope.numberOfPages = 23; //

Setting Angular $resource Config Globally

时光总嘲笑我的痴心妄想 提交于 2019-12-08 13:18:39
Based on the following sample, how can I set the $resource timeout and headers globally? I have a number of $resource definitions like the following but I’d prefer to not repeat the basic config for each. angular .module('myApp.services') .factory('myServices', myServices); myServices.$inject = ['$resource']; function myServices($resource) { return { serviceA: $resource('/api/serviceA', { serviceA_paramA: '@serviceA_valueA', serviceA_paramB: '@serviceA_valueB' }, { 'get': { method: 'GET', timeout: 120000 } }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }),

Add common parameter in each http request

偶尔善良 提交于 2019-12-08 07:04:27
问题 Suppose that all of my Rest API need to accept following parameters: 1) param1 2) param2 It would be tedious for me to implement this way (refer to code right below). Moreover, it defies the concept of DRY . What I am looking for is a global configuration that allows default parameter to be passed along with the http request. I believe that $httpProvider is the closest i can get (since it can define cookie expiry, header etc globally) but it seems that i could not find the way of using it to

Setting Angular $resource Config Globally

ε祈祈猫儿з 提交于 2019-12-08 07:00:17
问题 Based on the following sample, how can I set the $resource timeout and headers globally? I have a number of $resource definitions like the following but I’d prefer to not repeat the basic config for each. angular .module('myApp.services') .factory('myServices', myServices); myServices.$inject = ['$resource']; function myServices($resource) { return { serviceA: $resource('/api/serviceA', { serviceA_paramA: '@serviceA_valueA', serviceA_paramB: '@serviceA_valueB' }, { 'get': { method: 'GET',

angularjs $resource not replacing variable in url template for POST

喜夏-厌秋 提交于 2019-12-08 04:13:24
问题 Using AngularJS 1.2.16 and angular-resource 1.2.16. I have a resource like: $resource('api/:variable/path', { variable:'@variableName' }); When I do a get using something like resourceIns.get({variable:'taco'}); The resulting ajax call replaces :variable properly and i get api/taco/path If I do a post like resourceIns.save({variable:'taco'}); the resulting ajax call looks like api/path and 'taco' gets put in the POST body... I've had trouble finding others complaining about this so, maybe

With AngularJS, I don't want to set the global $http.defaults.headers.common. Can I send my custom header with each $resource call?

若如初见. 提交于 2019-12-07 10:10:43
问题 I'm calling a back-end server that I cannot control. Currently it's using jQuery ajax like this: return $.ajax({ type: "POST", url: "/api/cases/store", contentType: "application/json", data: JSON.stringify(parameters), headers: { "Authorization": cred } : {} }) // ... etc. I want to convert it to use the $resource service, and got it working doing this $http.defaults.headers.common['Authorization'] = cred; return $resource('/api/cases/store').save(); The only problem is that I'm having to set

How to read response from angular resource $save() and also keeping original data

早过忘川 提交于 2019-12-07 05:22:16
问题 I am new to Angular. I am sure I am missing some basic stuff here. I have one object which I post to the server to create it. The Server returns the object Id, which I need to read and update the object I have in the client. The server will only return the object ID, however, at the client side, I have other data which I am not able to use when I perform a callback (I don't have access to the original data). The Following jsfiddle code has been added as a reference: //Get Angular Project

Give kendo datasource an angular scope variable

泄露秘密 提交于 2019-12-07 03:01:26
问题 I'm currently trying to fill a kendo grid with remote data. Kendo has its own function to fetch the data, but I want to use the angular factory which I created. So I have a factory, which has a function "getSkills". This function obtains all the skill objects from my api. angular.module('MyApp').factory('Factory', function ($resource) { return $resource('/api/v1/skills/', { }, { getSkills: { method: 'GET', isArray: true } }); }); In my SkillController in angular, I put these fetched skills in

How can I get status code using $resource?

我的梦境 提交于 2019-12-06 22:01:38
My factory for making request is here: angular.module('myapp').factory('testResponse', ['$http', '$resource', 'AppConfig', '$routeParams', '$rootScope', function($http, $resource, $routeParams, $rootScope) { $http.defaults.headers.common['Authorization'] = authorizationHeader; $http.defaults.headers.post['Content-Type'] = 'application/json'; return $resource('test.json'), {}, { query: {method: 'GET'} }; }]); The code in controller is here: angular.module('myapp').controller('TestCtrl', ['$http', '$scope', 'testResponse', 'AppConfig', function TestCtrl($http, $scope, testResponse) {