Javascript 正在检查资源模块的删除和更新ui
如何检查下面的删除函数中实际发生的情况?每次我删除它都会显示“成功”,但UI不会更新 HTMLJavascript 正在检查资源模块的删除和更新ui,javascript,angularjs,rest,api,ngresource,Javascript,Angularjs,Rest,Api,Ngresource,如何检查下面的删除函数中实际发生的情况?每次我删除它都会显示“成功”,但UI不会更新 HTML {{head}} 控制器 $scope.deleteId = function (idPassed) { fileLoadService.delete({ 'id': idPassed.id }, function(successResult) { alert('Deleted'); }, function (errorResult) { // do something o
{{head}}
控制器
$scope.deleteId = function (idPassed) {
fileLoadService.delete({ 'id': idPassed.id }, function(successResult) {
alert('Deleted');
}, function (errorResult) {
// do something on error
if (errorResult.status === 404) {
alert('Ooops');
}
});
};
单击“删除”后,我的UI如下所示
文件加载服务
app.factory('fileLoadService', ['$resource',
function ($resource) {
return $resource(
"http://jsonplaceholder.typicode.com/todos/:id",
{ id: "@id" },
{ query: { 'method': 'GET', isArray: true }
});
}]);
您可以从代码中看到:
$scope.deleteId = function (idPassed) {
fileLoadService.delete({ 'id': idPassed.id },function(successResult) {
alert('Deleted');
}, function (errorResult) {
您对当前型号不做任何操作,只在点击删除按钮时发送一个警报Deleted
。如果你想让它做点别的。。。。。您应该将该功能放在代码中
例如:
$scope.deleteId = function (idPassed) {
fileLoadService.delete({ 'id': idPassed.id },function(successResult) {
var index = $scope.models.indexOf(idPassed);
$scope.models.splice(index, 1);
alert('Deleted');
}, function (errorResult) {
你应该更新你的
型号
删除你的意思是什么?这是一个由UI中的按钮调用的方法(deleteId(id))。fileLoad服务返回资源。我想念她什么?你的模型从未更新过。如果希望更改反映在当前屏幕上,则需要更新模型。请检查我上面发布的代码。谢谢,它在ui上工作,但不确定api是否在api上工作,因为当我重新加载页面时,它刚刚出现。jsonplaceholder api是否会暂时保持更改如果是这种情况,这是您的api或可能是fileLoadService的问题。这就是服务加载api应用程序工厂('fileLoadService',['$resource',function($resource){return$resource(“,{id:@id”},},{“查询”:{'method':'GET',isArray:true}};}]);