我的API后端在PHP中,为每个方法api打印一个json结果(GET,POST,PUT和DELETE)
示例:
/api/Download GET Print json result for all
/api/Download POST Print json result of new document
/api/Download/id GET Print json result from document
/api/Download/id PUT Print json result edited
/api/Download/id DELETE Print json result deleted
所有方法在PostMan或Restlet中都是成功的,在AngularJs中起作用的唯一方法是query()
API php中的结果:
header('Content-Type: application/json');
echo json_encode($result);
我的代码AngularJS:
app.factory('Download',function($resource){
return $resource('/api/Download/:id', {id: '@id'}, {
'get': {method:'GET'},
'save': {method:'POST'},
'update': {method:'PUT'},
'query': {method:'GET', isArray:true},
'delete': {method:'DELETE'}
});
});
我的控制器:
app.controller('ProductoController', function($scope, $http, Download) {
var d = new Download({
version: 123,
comentario: "test test"
});
d.$save();
});
$ save()中的错误是:
Error: $resource:badcfg
Response does not match configured parameter