angular - 无法在 Angular 中进行确认删除工作
问题描述
弹出确认框时尝试激活删除按钮,单击删除时应删除该行
我的删除功能如下,我将它复制到我的 popupcomponent ts 文件中:
deleteBilling(id: string) {
this.billingservice.deleteBilling(id).subscribe(
resp => {
console.log(resp);
this.displayBilling()
},
err => console.error(err));
}
我在实际按钮的popupcomponent html文件中复制了相同的内容:
<button type="button" class="btn btn-secondary" (click)="deleteBilling(billing.id)">Confirm Deletion</button>
为什么它不起作用?如果我删除弹出确认我的删除功能有效
我正在尝试将弹出窗口链接到删除功能:
popupTest(id: string) {
this.popupService.dialogOpen('Are you sure you want to delete?')
.afterClosed().subscribe(resp => {
//console.log(resp)
if (resp) {
//this.popupComponent.deleteBilling(id)??
//this.deletebilling(id)??
}
});
解决方案
当你说“在你的 popupcomponent ts 中复制了 deleteBilling 函数”时,你是什么意思?
如果您为弹出窗口使用组件并且删除逻辑在父级中,则需要发出一个事件:
将此添加到您的 popup.component.ts:
@Output() deleteEvent
deleteBilling(billing.id): void {
deleteEvent.emit(billing.id)
}
在父模板中:
<app-popup (deleteEvent)="deleteBilling($event)"></app-popup>
但是,我会考虑使用“模态”或对话框组件(实际弹出窗口)。这些通常在(父)组件中定义,因此不需要您向父组件发出事件。(角度引导和角度材料都是不错的选择。)
它们具有内置的所有功能,您应该能够找到很多关于它们的示例。
推荐阅读
- shell - 从一个文件中获取数据并使用 awk 将其发送到另一个文件
- excel - 修改循环以包含 3 个字符串
- python - 使用 Python 读取()图像文件并将其发送到 HttpResponse
- python - keras 迁移学习在之前添加一层并选择特定层作为输出
- python - 使用 Paramiko 将文件从 SFTP 传输到 S3
- python-3.x - 为什么魔术包可以通过 lan 而不是 wan 唤醒?
- laravel - 会话闪存消息在 Laravel 7 中不起作用
- oracle - 如何在arm设备上安装oracle客户端
- sql-server - 对包含聚合或子查询的表达式执行聚合函数
- arrays - 我的程序无法编译,谁能帮我在哪里修复