Angularjs immediately displays changes after deleting the promise data in the loop.
When restangurlar is used to interact with the background api, a record is deleted and displayed directly on the page. Third-party asynchronous data cannot be synchronized immediately. If you want to see the deletion result and refresh the page again, it will be too cool. google will find a solution.
The original js Code is as follows:
.controller('HostCtrl', ['$scope','Restangular',function($scope,Restangular) { var baseHosts = Restangular.all('api/host'); $scope.hosts=baseHosts.getList().$object; $scope.del=function(host,uuid){ Restangular.one('api/host',uuid).remove() }}])
Html:
delete {{host.Hostname}} {{host.Ip}} {{tcp_port}}
{{udp_port}}
The modified js Code is as follows:
.controller('HostCtrl', ['$scope','Restangular',function($scope,Restangular) { var baseHosts = Restangular.all('api/host'); $scope.hosts=baseHosts.getList().$object; $scope.del=function(host,uuid){ Restangular.one('api/host',uuid).remove().then(function(){ var index=$scope.hosts.indexOf(host); if(index > -1) $scope.hosts.splice(index,1); }) }}])