angularjs – 为什么此资源在使用$delete方法后没有更新视图
发布时间:2020-12-17 07:12:04 所属栏目:安全 来源:网络整理
导读:在我的角度应用程序中,我有一个控制器如下: function TemplateListControl($scope,TemplateService){ $scope.templates = TemplateService.get(); // Get objects from resource // Delete Method $scope.deleteTemplate = function(id){ $scope.templates.
在我的角度应用程序中,我有一个控制器如下:
function TemplateListControl($scope,TemplateService){ $scope.templates = TemplateService.get(); // Get objects from resource // Delete Method $scope.deleteTemplate = function(id){ $scope.templates.$delete({id: id}); } } 在视图中,我有一个绑定到模板模型的表.如下: <table ng-model="templates"> <thead> <tr> <th style="width:40%">Title</th> <th style="width:40%">controls</th> </tr> <thead> <tbody> <tr ng-repeat="template in templates"> <td> <!-- Link to template details page --> <a href="#/template/[[template.id]]"> [[template.title]] </a> </td> <td> <!-- Link to template details page --> <a class="btn btn-primary btn-small" href="#/template/[[template.id]]">Edit </a> <!-- Link to delete this template --> <a class="btn btn-primary btn-small" ng-click="deleteTemplate(template.id)">Delete </a> </td> </tr> </tbody> </table> 现在当我点击上面模板中的删除链接时,它调用了deleteTemplate方法,并且对REST api进行了成功的DELETE调用.但是在刷新并且$scope.templates = TemplateService.get()之前,视图不会更新.再次发起.我究竟做错了什么? 解决方法
您还必须更新客户端,因此请修改源代码,如下所示
ng-click="deleteTemplate($index)"> $scope.delete = function ( idx ) { var templateid = $scope.templates[idx]; API.Deletetemplate({ id: templateid.id },function (success) { $scope.templates.splice(idx,1); }); }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |