资源更新回调
Callback for resource update
下面是我的代码。当我在保存方法中使用它时它工作正常但在更新时,它给我一个错误 TypeError: Cannot read property 'then' of undefined
服务
.factory('Details', function($resource, HostUrl){
return $resource(HostUrl + '/api/v1/details/:id' , { id: '@id' } ,{
update: { method: 'PUT' }
});
})
控制器
function updateStatus(details_id,status_id){
var details = Details.get({id: details_id});
details.status_id = status_id;
details.$update({id: details_id})
.$promise.then(function(data){
// Success
},
function(error){
// Error
});
}
如何正确执行此操作?谢谢
你不需要使用 promise,这个解决方案会起作用
Details.update({id: details_id}, function (response) {
//success function
}, function (response) {
//error function
});
下面是我的代码。当我在保存方法中使用它时它工作正常但在更新时,它给我一个错误 TypeError: Cannot read property 'then' of undefined
服务
.factory('Details', function($resource, HostUrl){
return $resource(HostUrl + '/api/v1/details/:id' , { id: '@id' } ,{
update: { method: 'PUT' }
});
})
控制器
function updateStatus(details_id,status_id){
var details = Details.get({id: details_id});
details.status_id = status_id;
details.$update({id: details_id})
.$promise.then(function(data){
// Success
},
function(error){
// Error
});
}
如何正确执行此操作?谢谢
你不需要使用 promise,这个解决方案会起作用
Details.update({id: details_id}, function (response) {
//success function
}, function (response) {
//error function
});