Javascript 如何通过单击按钮2从表中删除特定行

Javascript 如何通过单击按钮2从表中删除特定行,javascript,angular,html-table,Javascript,Angular,Html Table,我试图通过单击for循环中该行的按钮来删除某一行,但它会删除该表的所有行 以下是我的Html代码: <table id="mytable" class="table table-bordred table-striped"> <tbody id="del"> <tr *ngFor="let cart of modalData"> <td> <div style="

我试图通过单击for循环中该行的按钮来删除某一行,但它会删除该表的所有行

以下是我的Html代码:

<table id="mytable" class="table table-bordred table-striped">
    <tbody id="del">
        <tr *ngFor="let cart of modalData">
            <td>
                <div style="display:inline-flex;">
                    <div style="margin-left:10px;">
                        <p class="font_weight" style="font-size:13px;">{{cart.ExamName}}</p>
                        <p>{{cart.Categoryname}}|{{cart.CompanyName}}</p>
                    </div>
                </div>
            </td>
            <td>
                <div style="margin-top: 32px;">
                    <p class="font_weight" style="font-size:13px;"></p> <span class="font_weight" style="font-size: 13px;"> {{cart.Amount| currency :'USD':'true'}} </span> </div>
            </td>
            <td>
                <div style="margin-top: 19px;">
                    <button class="button_transparent" (click)="Delete(cart)"> delete </button>
                </div>
            </td>
        </tr>
        <tr> </tr>
    </tbody>
</table>
这是我的删除方法:

public Delete(response) {
     this.myCartService.updateExamOrder(response)
     .subscribe(response => this.getDataOnSuccessForDelete(response),
     response => this.getDataOnErrorForDelete(response));
} 

请帮我做一下,如何从表中只删除一行

您可以在*ngFor中添加
索引

<tr *ngFor="let cart of modalData;let i = index">

您可以在*ngFor中添加
索引

<tr *ngFor="let cart of modalData;let i = index">
您可以这样做:

删除

然后

您正在创建一个新列表,其中不包含要删除的元素。

您可以执行以下操作:

删除

然后


在这里,您正在创建一个没有要删除的元素的新列表。

您的意思是从上到下逐个删除?您可以发布您的删除方法吗?公共删除(响应){this.myCartService.updateExamOrder(响应).subscribe(响应=>this.getDataOnSuccessForDelete(响应),response=>this.getDataOneRorfordelete(response));}这是我的删除方法你的意思是从上到下一个一个地删除吗?你能发布你的删除方法吗?public delete(response){this.myCartService.updateExamOrder(response).subscribe(response=>this.getDataOnSuccessForDelete(response),response=>this.getDataOnErrorForDelete(response));}这是我的删除方法是的,我知道了,谢谢你出了什么问题?是的,我知道了,谢谢你出了什么问题?
<button class="button_transparent" (click)="delete(i)"> delete </button>
delete(i){
  this.modalData.splice(i,1);
}
delete(item){
    this. modalData = this. modalData.filter(item => item.id !== id);
    this.modalData.push();}