【问题标题】:How to close the previous confirm box and open new one on accept or reject in PrimNg如何在 PrimNg 中关闭之前的确认框并在接受或拒绝时打开新的确认框
【发布时间】:2021-07-21 14:57:24
【问题描述】:

我必须确认单击接受按钮打开新确认框的框。

当我尝试调用接受方法时,它没有调用新的确认框,有什么办法可以得到吗?

下面是stackblitz供参考。

https://stackblitz.com/edit/primeng-confirmdialog-demo-stzy7i

【问题讨论】:

    标签: angular primeng


    【解决方案1】:

    您正在尝试使用相同的引用打开确认对话框。执行accept 回调时,旧对话框仍然打开(我猜是因为动画)。

    您需要为每个对话框创建不同的p-confirmDialog 以使它们完全独立(使用key 属性)。

    StackBlitz fork

    模板:

    <p-confirmDialog key="confirm1" [style]="{width: '50vw'}" [baseZIndex]="10000"></p-confirmDialog>
    <p-confirmDialog key="confirm2" [style]="{width: '50vw'}" [baseZIndex]="10000"></p-confirmDialog>
    <p-button (click)="confirm1()" icon="pi pi-check" label="Confirm"></p-button>
    <p-button (click)="confirm2()" icon="pi pi-times" label="Delete"></p-button>
    

    打字稿:

    confirm1() {
        this.confirmationService.confirm({
          key: 'confirm1',
          message: 'Are you sure that you want to proceed?',
          header: 'Confirmation',
          icon: 'pi pi-exclamation-triangle',
          accept: () => {
            this.confirm2();
            // this.msgs = [{severity:'info', summary:'Confirmed', detail:'You have accepted'}];
          },
          reject: () => {
            this.msgs = [
              { severity: 'info', summary: 'Rejected', detail: 'You have rejected' }
            ];
          }
        });
      }
    
    confirm2() {
        this.confirmationService.confirm({
          key: 'confirm2',
          ...everythingElse
        });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      相关资源
      最近更新 更多