panagulis72
panagulis72

Reputation: 2169

Remove checked row Angular

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!

Upvotes: 1

Views: 2467

Answers (2)

Mahaboob Subhani
Mahaboob Subhani

Reputation: 9

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--; 
              }
          }             
      }`

Upvotes: 1

Qi Tang
Qi Tang

Reputation: 1165

You can do something like this

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

Here is an example

Upvotes: 3

Related Questions