我正在尝试将json数据发布到我的服务
{"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;
});
}
]);
虽然请求以POST形式发送,但我没有看到请求正文中附加的上述JSON数据。我错过了什么吗?
答案 0 :(得分:1)
您无法默认发布数据,您需要将其传递给...
searchFactory.update({"firstName":"John"}, function(response) {
$scope.users = response;
});
文档:http://code.angularjs.org/1.2.15/docs/api/ngResource/service/$resource