javascript - primeng确认服务多次通话

标签 javascript angular angular6 primeng

我使用 PrimeNg 和 Angular 6 来生成一个确认框,用于从表单中删除项目,并保存对表单所做的所有更改。当

delete() {
  this._confirmationService.confirm({
     message: 'Delete Item?',
     key: 'delete',
     accept: () => {
       // code to delete row
     }
  });
}

submit() {
  this._confirmationService.confirm({
     message: 'Save Changes',
     key: 'submit',
     accept: () => {
       // code to save changes
     }
  });
}

html

<button pButton (click)="delete()"></button>
<button pButton (click)="submit()"></button>

<p-confirmDialog key="delete"></p-confirmDialog>
<p-confirmDialog key="submit"></p-confirmDialog>

当不使用按键时,两个按钮都会调用提交确认函数。使用按键时,提交按钮会调用提交确认,但在接受时会陷入循环,而删除函数会调用提交确认,如果被拒绝,则会调用删除确认。

我需要做什么才能只调用特定于该函数的确认服务?

最佳答案

在拒绝确认对话框时,我遇到了类似的问题,我必须单击 10 次才能退出对话框。 事实证明,我只是错过了拒绝事件上的 confirmationService.close():

confirmDelete(index: number): void {

    this.confirmationService.confirm({
      message: 'Are you sure you want to delete the parameter?',
      accept: () => {
        this.deleteParameter(index);
      },
      reject: () => {
        this.confirmationService.close();
      }
    });
}

关于javascript - primeng确认服务多次通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53860167/

相关文章:

Angular 模板 : How to bind RXJS Observable and read its properties?

javascript - Jquery 文档准备好动态加载的 HTML 会提前触发

javascript - 如何在 DataView 中设置有符号的 24 位整数?

javascript - 从 Javascript 中的字符串获取 URL 值

javascript - 更改 "md-menu"的 Angular 2/4 Material 默认样式

javascript - 当您使用来自 "ExpressionChangedAfterItHasBeenCheckedError"的信息时,如何避免 "Cannot Read Property of Undefined"或 "@ViewChild"?

angular - 当 BehaviorSubject 值 === false 时延迟可观察流

angular - 使用renderer.js和 Angular 组件使用的 Angular/Electron

javascript - 当满足某些 php 条件时动态激活菜单

django - 如何在 Python Django 中托管 Angular 6 应用程序?