Angularjs immediately displays changes after deleting the promise data in the loop.

Source: Internet
Author: User

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);        })        }}])

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.