Angularjs 使用$resource发布正文

Angularjs 使用$resource发布正文,angularjs,angular-resource,Angularjs,Angular Resource,如何使用带有角度$resource的有效负载主体执行正常的POST。现在,当我发布时,它会发布到/api/example?name=JoeSmith&is_whatever=false,而不是用正文发布 假设我有以下几点: ENDPOINT: `/api/example` BODY: { "name": "Joe Smith", "is_whatever": false } API服务 angular.module('example') .factory('APIServic

如何使用带有角度
$resource
的有效负载主体执行正常的
POST
。现在,当我发布时,它会发布到
/api/example?name=JoeSmith&is_whatever=false
,而不是用正文发布

假设我有以下几点:

ENDPOINT: `/api/example`
BODY: {
   "name": "Joe Smith",
   "is_whatever": false
}
API服务

angular.module('example')
   .factory('APIService', ['$resource',

        function($resource) {

           return $resource('/api/example', {}, {
              create: {
                 method: 'POST',
              }
           });          

        }]);
    // body i need to POST
    var payload = {
       name: 'Joe Smith',
       is_whatever: false        
    };

    APIService.create(payload).$promise.then(function(res){
        // doesnt work
    });
示例用法

angular.module('example')
   .factory('APIService', ['$resource',

        function($resource) {

           return $resource('/api/example', {}, {
              create: {
                 method: 'POST',
              }
           });          

        }]);
    // body i need to POST
    var payload = {
       name: 'Joe Smith',
       is_whatever: false        
    };

    APIService.create(payload).$promise.then(function(res){
        // doesnt work
    });

尝试将数据参数传递给资源的操作方法,如下所示:

angular.module('example', ['ngResource'])

.run(function(APIService) {
   var payload = {
      name: 'Joe Smith',
      is_whatever: false        
   };
   APIService.save({}, payload)
})

.factory('APIService', function($resource) {
   return $resource('/api/example');
});

这是否有效:
APIService.create({},payload)。$promise.then(…)
第一个参数应该是params或blank{},然后是有效负载`APIService.create({},payload)。$promise.then(函数(res){//doesnt work})`