Reputation: 2169
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
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