1

I have a list of field in row. The user can add the row. How can I make a function which removes the checked rows? I was thinking to add to them in a new array, but I don't know how to filter the selected item.

http://plnkr.co/edit/S2tudP0kJcVUiKZKRa7j?p=preview

  <body ng-controller="DuplicateInputCtrl" class="container">
<div data-ng-repeat="food in foods">
  <div class="form-group title-field">
    <label for="">Food</label>
    <select class="form-control input-full" data-ng-model="food.Selection"
        data-ng-options="foodType.code as foodType.type for foodType in foodTypes">
        <option value="">Select</option>
    </select>
    <input type="hidden">
    <button data-ng-click="removeItem($index)" class="btn delete-field-{{$index}}">
      Delete
    </button>
  </div>
  <div class="form-group">

        <input style="background: white; color: black;" type="text" id="myInput"  class="form-control" data-ng-model="food.Text"/>

    </div>
</div>
{{foods | json}}
<button data-ng-click="cloneItem()" class="btn inline">
  Add
</button>    
    <button data-ng-click="" class="btn inline">
  Remove Selected
</button>  

Thank you!

2 Answers 2

3

You can do something like this

 $scope.removeSelected = function() {
            $scope.foods = $scope.foods.filter(function(food){
                return !food.selected
            })
          }

Here is an example

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much! But i was thiking to add it in new array because i want to implements that script with with another one, that generate a barcode for each row pressing the button "UPDATE".. but how can i do it just for the checked one? plnkr.co/edit/v9ETdTA5dJhFl7IX0kpY?p=preview Because at the end i will do just a unique button that print in a new windows the barcodes of the checked rows
Why do you want to add the selected items to a new array if you just want to remove them. I don't quite get what you said
I don't need it, forget it :) I just thought it could help. Anyway, the target that i wanted is: the user can add some rows. At the end of all the table, the user has 2 button: PRINT SELECTED and REMOVE SELECTED. So, if the user check 3 rows, he can remove (and you showed me how with that funciton) and he can print the barcode of these 3 checked rowes. Now, the scirpt that i've made creates the barcode for each rows, everytime you press update
1
Use the following function on remove selected button click 
`$scope.removeSelectedItems = function () {
          for (var i = 0; i < $scope.foods.length; i++) {                 
              if ($scope.foods[i].selected == true) {
                  $scope.foods.splice(i, 1);
                  i--; 
              }
          }             
      }`

1 Comment

Thank you! I like this one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.