Angularjs 如何在我的案例中创建POST请求?
我正试图通过Angular中的Angularjs 如何在我的案例中创建POST请求?,angularjs,http,service,Angularjs,Http,Service,我正试图通过Angular中的$resource对象发出POST请求 我有点像 (function (angular) { angular.module('myApp') .factory('myService', [ '$resource', function ($resource) { var serviceObj = $resource('http://testProject/produc
$resource
对象发出POST
请求
我有点像
(function (angular) {
angular.module('myApp')
.factory('myService', [
'$resource',
function ($resource) {
var serviceObj = $resource('http://testProject/products/', {id: '@id'},{
'createItem' : {
url: 'http://testProject/item/:id',
method: 'POST',
params: {type: ‘@type'}
}
});
return serviceObj;
}
]);
})(angular);
在我的控制器中
//omit the controller codes…
myService.type = ‘Detail’;
myService.createItem(function(data) {
console.log(data)
});
我在
控制台.log中看到了返回的内容,但它的数据错误,因为类型显示为“Name
”,而不是“Detail
”。我知道api支持这一点,我认为我的服务没有任何问题。有人能帮我吗?非常感谢 看起来您的数据正在恢复
我会尝试:
console.log(data.data);
因为您正在从服务返回一个对象