angularjs-resource

Send null as a value in ngResource AngularJS

一曲冷凌霜 提交于 2019-12-23 07:58:11
问题 I'm using AngularJS 1.2.1's ngResource and I'm trying to send null as a value in the parameters in a PUT request. Unfortunately, when it is set, Angular will ignore it the parameter and not send it. Here's some example code: var User = $resource('/comments/:id', {id:'@id'}, { destroy: { method: 'PUT', params: {content: null} } }); var user = User.destroy({id:123}, function() {}); Angular will instead ignore content and not send the key nor the null value. How can I make Angular send null? 回答1

How to refresh / invalidate $resource cache in AngularJS

时间秒杀一切 提交于 2019-12-17 07:04:18
问题 I have a simple User $resource that uses the default $http cache implementation like so: factory('User', function($resource){ return $resource(endpoint + '/user/current/:projectId', {}, {get: { cache: true, method: 'GET' } } ); }) This works very well, i.e. my server is only called once in my application, then the value is fetched from cache. But I need to refresh the value from the server after a certain operation. Is there an easy way to do that? Thanks. 回答1: Keep the boolean and get the

How to configure Angular $resource (ngResource) to pull data from another domain using CORS

拜拜、爱过 提交于 2019-12-14 03:39:47
问题 I'd like to be able to setup resources using $resource using CORS to request my data. I've got CORS working with $http but the same techniques don't apply to $resource and I was hoping someone can come to my rescue and show me how with $resource. I've modified the last step of the Angular tutorial to use CORS by hacking the phonecatServices service, in the services.js file. I found this example which uses the $http.defaults.useXDomain = true; delete $http.defaults.headers.common['X-Requested

AngularJS $resource url causes “question mark” ? to appear with no params

爱⌒轻易说出口 提交于 2019-12-13 13:22:19
问题 I have a $resource that defines a custom url for the :all method. angular.module('MyApp'). factory('Object', ['$resource', ($resource) -> $resource( '/api/groups/:group_id/objects/:id.json', { id: '@id', group_id: '@group_id' }, all: { method: 'GET', url: '/api/objects/all.json' } ) ]) When my page loads, the request goes out to '/api/objects/all.json?'. It's loading correctly, but the presence of the ? is confusing to me. I didn't pass it any parameters, so why does angular add the ? to the

I am getting a $save() not a function in Angular

不问归期 提交于 2019-12-13 05:01:39
问题 I am trying to build a relatively simple web application following tutorials from the book ProAngular. The book examples work fine, but when I try and build my own app, I am getting stuck on a strange error. Here is part of my code: $scope.dispositionsResource = $resource(dispositionUrl + ":id", { id: "@id" }, { create: {method: "POST"}, save: {method: "PUT"}, delete: {method: "DELETE"} }); . . . $scope.updateDisposition = function (disposition) { alert("DISPOSITION: "+disposition.name);

AngularJS 1.2.0 $resource response is empty

扶醉桌前 提交于 2019-12-12 16:14:49
问题 I'm using AngularJS 1.2.0. When I'm calling a webservice with $resouce the response variable is always empty. The webservice is called correctly and the webservice is sending the result to the browser. The problem is that (callback(response){}) response is always empty. angular.module('app').factory('geoCoding',['$resource', function ($resource) { return $resource('http://open.mapquestapi.com/geocoding/v1/address', {key: getGeoKey()}, { locate: {method: 'GET', isArray: false} }); }]); $scope

Getting fields from JSON using Angularjs

血红的双手。 提交于 2019-12-12 01:44:44
问题 This is a very simple question but I'm writing a webpage that's supposed to display the user's information. There will be fields of name, id, role, etc. I want to write setter and getter methods for the JSON that I receive from the database. For example, if I get a JSON and I want to get and display the name field, how would I write this getter method in angularJS after getting the JSON from a $resource service? This is an example of how the JSON would look: [{"name": "Jason" "date of birth":

set default/additional payload in ngResource

孤者浪人 提交于 2019-12-12 01:12:27
问题 I have following resource defined as a service named 'User': return $resource('/user', {}, { login: { url: 'user/login', method: 'PUT', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } } }); and I can use it for logging in inside controller as follows: User.login({ Password: $scope.password, UserName: $scope.name, OsModel: Os.model, OsVersion: Os.version }); (Os is another service providing some values). the problem is that this resource is gonna be used in some

AngularJS $resource DELETE item in collection

陌路散爱 提交于 2019-12-11 14:24:19
问题 I have an ASP.NET Web Api (1) controller with GET, POST and DELETE actions. I am calling this from an Angular 1.2.0 RC3 app with $resource . Let's call the controller Foos . I do a GET that returns a list of foos: GET http://localhost:55386/api/foos/123456/1 HTTP/1.1 Host: localhost:55386 Connection: keep-alive Accept: application/json, text/plain, */* Origin: null User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 Accept

Passing param object from $resource get method to restful services

痴心易碎 提交于 2019-12-10 12:01:04
问题 i have query regarding passing param objects to $resource get method. in the backend restful application i am not getting the routeparam values passed . here my sample code on clicking the search button from the html page it is moving to controller as mentioned in myapp.js myapp.js var app = angular.module('myApp', [ 'MyServices']); app.config([ '$routeProvider', function($routeProvider) { $routeProvider .when('/employeesearch/:empID/:deptID', { templateUrl : 'partials/result.html',