Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 刷新ng repeat,不带$scope,不带新的服务器请求_Angularjs_Angularjs Ng Repeat_Angularjs Controlleras - Fatal编程技术网

Angularjs 刷新ng repeat,不带$scope,不带新的服务器请求

Angularjs 刷新ng repeat,不带$scope,不带新的服务器请求,angularjs,angularjs-ng-repeat,angularjs-controlleras,Angularjs,Angularjs Ng Repeat,Angularjs Controlleras,我有一个包含以下内容的表格: <tbody> <tr ng-repeat="result in ctrl.result track by $index"> <td ng-bind="$index+1"></td> <td ng-bind="::result.title"></td> <td> <button type="button" class="bt

我有一个包含以下内容的表格:

 <tbody>
     <tr ng-repeat="result in ctrl.result track by $index">
       <td ng-bind="$index+1"></td>
       <td ng-bind="::result.title"></td>
       <td> <button type="button" class="btn" ng-click='ctrl.deleteItem(result)'>Delete</button></td>
     </tr>
 </tbody>  
如您所见,如果成功删除该项,
vm.result
已更改。 现在,该项在db中被删除,因此我们有了响应,然后该项也从
vm.result
中被删除。但该列表尚未在浏览器中更新。

如您所见,我使用
控制器作为
方法,而不是
$scope

尝试以下方式删除该项:

vm.result.splice(vm.result.indexOf(result), 1);
第一个参数应该是元素的索引,而不是元素本身

     var index = vm.result.findIndex(function(item) {
                if (item.id == test.id) {
                    return true;
                }
            });

            if (index !== -1) {
                // Removing the test from list;
                vm.result.splice(index, 1);
}

检查基于数组测试的id。id是正在删除的元素的id。您好,您必须在html中使用vm.result,因为在您的控制器中,如果只有$scope.result,则只有vm.result才会被视为html中的结果,因此在html中更改vm.result您应该尝试从
ng bind
中删除
。因为它不仅仅是只读数据@gayathri,我已将myController设置为ctrl。所以我使用虚拟机。在控制器中,按ctrl键。在html中,@DhavalMarthak,++投票支持您的评论!我接受了答案。但是@Dhaval Marthak的评论也对我有所帮助。如果我不删除:,它就不会工作。@Elnaz很高兴它有帮助:)
     var index = vm.result.findIndex(function(item) {
                if (item.id == test.id) {
                    return true;
                }
            });

            if (index !== -1) {
                // Removing the test from list;
                vm.result.splice(index, 1);
}