均值堆栈删除回调 [英] Mean Stack delete callback
本文介绍了均值堆栈删除回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的平均堆栈删除功能正常运行;但是,一旦删除,我似乎无法弄清楚如何使用更新后的JSON更新视图.
I have my Mean stack delete functioning properly; however, I can't seem to figure out how to update the view with the updated JSON once deleted.
我的快速服务器端逻辑:
My express server side logic:
.delete(function(req, res) {
Service.remove({
_id: req.params._id
}, function(err, service) {
if (err)
res.send(err);
res.json({ message: 'Successfully deleted' });
});
});
我的角度控制器
$scope.removeItem = function(id) {
$http.delete('/api/hc/' + id)
.success(function(data) {
$scope.services = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
我的角度模板调用函数
<a ng-click="removeItem(service._id)">Remove</a>
推荐答案
我实际上是通过将成功函数中的逻辑替换为之前设置的查询函数来使它起作用的
I actually just got it working by replacing the logic in the success function with my query function set up earlier
$scope.removeItem = function(id) {
$http.delete('/api/hc/' + id)
.success(function(data) {
HC.API.query(function(results) {
$scope.services = results;
});
})
.error(function(data) {
console.log('Error: ' + data);
});
};
这是HC.API所引用的:
Here's what HC.API is referencing:
app.factory("HC", ["$resource", function($resource) {
return {
API: $resource('/api/hc/:id')
}
}]);
由于我在同一函数中同时使用了$ http和$ resource,因此可能有更正确的方法.
There's likely a more correct way to do this since I'm using both $http and $resource in the same function.
这篇关于均值堆栈删除回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文