我正在尝试在Angular项目中使用Bootsrap Modal询问“您确定删除此项目”
但是当我将itemID发送到模态时,即使我选择要删除的第4个项目,也始终会得到第一个itemId
<div class="col-sm-3" *ngFor="let item of florArray">
<div class="card shadow p-1 mb-2 bg-white rounded" style="width: 100%;">
<div class="card-body">
<h3>{{item.cubeAreaName}}</h3>
<hr>
<br>
<button class="btn btn-warning btn-block" (click)="editZone(item.cubeAreaID)" type="submit">Edit</button>
<button class="btn btn-danger btn-block" data-toggle="modal" data-target="#exampleModalCenter" type="submit">Delete</button>
</div>
</div>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Delete It ?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
If you delete this section please dont forget that you will lose your all related tables that you have
created for this section
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger" data-dismiss="modal" (click)="deactiveZone(item.cubeAreaID)">Delete</button>
</div>
</div>
</div>
</div>
认为我有五个列出的项目。然后我单击了第四项以删除。
(click)=“ deactiveZone(item.cubeAreaID)
模式按钮中存在的此代码部分始终删除第一项。
你能告诉我我的错误在哪里吗?
答案 0 :(得分:1)
引导程序模式不能那样工作。我周围也有同样的问题。您可以做的就是将ID存储在一个临时变量中并使用它。
TS:
. . .
tempIDSelect : number
. . .
HTML:
. . .
// Button to toggle delete modal
<button class="btn btn-danger btn-block" data-toggle="modal" data-target="#exampleModalCenter" type="submit" (click)="tempIDSelect=item.CubeAreaID">Delete</button>
. . .
// Button inside modal
<button type="button" class="btn btn-danger" data-dismiss="modal" (click)="deactiveZone(tempIDSelect)">Delete</button>
. . .