Reputation: 695
I am trying to post json data to my service
{"firstName":"John"}
Services.js
var AppServices = angular.module('App.services', [ 'ngResource' ]);
AppServices.factory('searchFactory', [ '$resource', function($resource) {
return $resource('rest/search', {}, {
update : {
data : {
'firstName' : 'john'
},
method : 'POST',
headers : {
'Content-Type' : 'application/json'
}
}
});
} ]);
controller.js
var AppControllers = angular.module('App.controllers', []);
AppControllers.controller('SubmitCtrl', [ '$scope', 'searchFactory',
function($scope, searchFactory) {
searchFactory.update(function(response) {
$scope.users = response;
});
}
]);
Although the request is going out as POST, I don't see above JSON data appended in request body. Am I missing something?
Upvotes: 0
Views: 236
Reputation: 37520
You can't default the post data, you need to pass it in...
searchFactory.update({"firstName":"John"}, function(response) {
$scope.users = response;
});
Docs: http://code.angularjs.org/1.2.15/docs/api/ngResource/service/$resource
Upvotes: 1