primeng确认服务多次通话

bjw*_*hip 1 javascript primeng angular angular6

我使用 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
     }
  });
}
Run Code Online (Sandbox Code Playgroud)

html

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

<p-confirmDialog key="delete"></p-confirmDialog>
<p-confirmDialog key="submit"></p-confirmDialog>
Run Code Online (Sandbox Code Playgroud)

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

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

小智 5

我在拒绝确认对话框时遇到了类似的问题,我必须单击 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();
      }
    });
}
Run Code Online (Sandbox Code Playgroud)