Ich habe eine Tabelle mit einigen Beispieldaten. Ich habe eine Schaltfläche, mit der ich in der Tabellenzeile verwenden möchte, die die gesamte Tabellenzeile entfernt, wenn auf sie geklickt wird. Problem ist, was ich oben programmiert habe, wird den Inhalt von der Tabellenreihe entfernen und die Knopf- und Tabellenreihe lassen. Oder es wird die letzte Tabellenzeile die Zeile nicht entfernen Sie die Taste in geklickt wurdeGesamte Tabellenzeile entfernen angularjs button
Hier ist, was ich habe.
Controller:
$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>
Detaillierte Gegenstand Löschen ausgewählter Tabellenzeile in AngularJS https://codepedia.info/angularjs-delete-table-row-tr-on-click/ –