Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Refresh data in ng-Repeat after Delete Or Update Records

I am new in angularJs.. I have One Query How to refresh data in ng-Repeat

My View Look Like This :

My view

Now, I Press the Delete Button Event then the Record Not Remove From Grid ...

View Description

$scope.Deletepovider = function (ProviderListId) {
    if (confirm('Are you sure you want to delete this?')) {
        var getmsg = AdminService.DeleteProviderDetail(ProviderListId, '/Admin/Delete', $scope.onDeleteCompleted, $scope.onDeleteError);
        return true;
    } else {
        e.stopImmediatePropagation();
        e.preventDefault();
        return false;
    }
}
$scope.onDeleteCompleted = function (response, status) {}
$scope.onDeleteError = function (response, status) {}
like image 645
Ravi Shah Avatar asked Dec 27 '25 23:12

Ravi Shah


1 Answers

I would say, in general, you don't want to "refresh" your list after performing an operation like this. Rather, you want to manage the list it's bound to. Consider something like this:

$scope.Deletepovider = function (ProviderListId)
{
  if (confirm('Are you sure you want to delete this?'))
  {
    var getmsg = AdminService.DeleteProviderDetail(
      ProviderListId,
      '/Admin/Delete',
      function () {
        // remove the provider from the list the ng-repeat is bound to
        // you could use anything like lodash or underscore to find the
        // provider by ID (referencing ProviderListId above)
      },
      function(err) {

      });
    return true;
  }
  else
  {
    e.stopImmediatePropagation();
    e.preventDefault();
    return false;
  }
}

NOTE: take notice to the comments I added in the success callback. That's your solution.

like image 53
Mike Perrenoud Avatar answered Dec 30 '25 13:12

Mike Perrenoud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!