Patrick Muñoz Vargas Patrick Muñoz Vargas - 9 months ago 58
AngularJS Question

AngularJs How to update data table without reloading page

I have the following array in my controller that gets objects from the database:

this.objects = [ //data of array goes here ];

Then I have an html table:

<tbody ng-repeat="object in object.recipients>

The table is displayed correctly. And I have a delete button that removes objects from the database. But in order to see the changes on my table, I need to refresh the page. How can I have my table updated without refreshing?


Just delete using a controller function that does:

this.objects.splice(index, 1)

and in your delete button in html, call the delete function and pass the index, or another unique id. e.g

<button ng-click="deleteThis($index)">Delete</button>

$index refers to the current index in the ng-repeat

If you prefer, you can delete from your server, and if success callback/promise is resolved, then delete from the view as explained above