question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delete selected row with ng-click="delete($event)"

See original GitHub issue

How do you use delete($event) to remove a checked row from the table? In my app.js I have the following:

$scope.delete = function(item) { var index = $scope.data.indexOf(item); $scope.data.splice(index, 1); }

But this only removes the last item

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daniel-nagycommented, Jun 9, 2016

All the selected items will be placed in your model. So if you have

<table md-table md-row-select multiple ng-model="selected">

Whenever an item is selected it will be pushed on to the selected array. If you want to delete all the selected items just loop through the selected array.

$scope.delete = function () {
  $scope.selected.forEach(function (item) {
    var index = $scope.data.indexOf(item);

    if(index !== -1) {
      $scope.data.splice(index, 1);
    }
  });
};

This is only a client side delete. If you want to delete them on the back end then just send a DELETE request for each selected item.

0reactions
rafaelhccommented, Jun 10, 2016

You are a hero, thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to delete the row in which a ng-click is located?
What is the best way to do this? Do I need to send the row as a parameter to deleteCustomer somehow? Do I...
Read more >
How to delete an item or object from the array using ng-click
The task is to delete the item from the list when the button is clicked. This all should be done by using ng-click....
Read more >
Delete Selected Row on click of delete button - Wijmo
I'm trying to delete entire selected rows (which i'm getting from getSelectedRows() function and my row contains both readonly and editable ...
Read more >
AngularJS: Delete Table Row tr on button click - Codepedia.info
Here on click of delete button our deleteRow() function gets fire and using splice we remove the selected rows. ... Conclusion: Directive ng- ......
Read more >
Part 6: Delete record by button click in Angular - YouTube
CRUDOperations #SpringBoot # Angular #StudentApplicationThis is how to delete selected student record by clicking delete button in angular.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found