Mam tabelę z przykładowymi danymi. Mam przycisk, którego chcę użyć w wierszu tabeli, który usunie cały wiersz tabeli po kliknięciu. Problem w tym, że zakodowałem, usunę zawartość z wiersza tabeli i zostawię przycisk i wiersz tabeli. Lub usunie ostatniej tabeli nie wierszu wiersz przycisk został kliknięty wUsuń cały wiersz tabeli przycisk angularjs
Oto co mam:.
kontroler:
$scope.removeRow = function (product) {
var index = -1;
var productArray = eval($scope.products);
for (var i = 0; i < productArray.legnth; i++) {
if (productArray[i].productName == product.productName) {
index = i;
console.log(productArray[i].productName);
}
}
if (index === -1) {
alert("something broke");
}
$scope.products.splice(index, 1);
}
html
<table class="table table-bordered table-hover">
<tr>
<!--<th><button class="btn btn-primary" type="button" data-ng-click="showImage = !showImage">{{showImage ? "Hide" : "Show"}} Image</button></th>-->
<th>Show or Hide </th>
<th>Product</th>
<th>Code</th>
<th>Avaiable</th>
<th>Price</th>
</tr>
<tr data-ng-repeat="product in products">
<td><input type="button" class="btn btn-primary" value="Hide" data-ng-click="removeRow(product)"/></td>
<td>{{product.productName}}</td>
<td>{{product.productCode}}</td>
<td>{{product.releaseDate}}</td>
<td>{{product.price | currency}}</td>
</tr>
</table>
Szczegółowy artykuł dotyczący usunięcia wybranego wiersza tabeli w AngularjS https://codepedia.info/angularjs-delete-table-row-tr-on-click/ –