Angular PrimeNG p-confirmDialog 显示两次

Las*_*zlo 4 dialog display primeng angular

当确认对话框显示两次时是哪种情况?或者从其他方面来说,确认对话框显示两次的原因是什么?

我有一个简单的对话框模板

<p-confirmDialog icon="fa fa-exclamation-triangle"
                 width="444"
                 [closable]="false"
                 key="uniqueidofdialog"
                 appendTo="body"
                 #dialogref>
  <p-footer>
    <button id="gemini_consentLockedByAnotherUser_btnOk"
            type="button"
            pButton
            class="button-primary"
            label="OK"
            (click)="dialogref.accept()"></button>
  </p-footer>
</p-confirmDialog>

  private showConfirmDialog() {
    this.confirmationService.confirm({
      message: `Warning! blah-blah.`,
      header: `Warning header`,
      key: 'uniqueidofdialog',
      accept: () => {
        // TODO
      }
    });     
  }
Run Code Online (Sandbox Code Playgroud)

当然,ComfirmationService 包含在模块的提供者部分中,而 ComfirmDialogModule 则导入到模块的导入部分中。showConfirmDialog() 调用一次。

我错过了什么?

先感谢您

Fla*_*ken 7

如果您没有提供任何密钥,您也可以ConfirmationService只为您的组件提供 来解决此问题

@Component({
  providers: [ConfirmationService], // <- inject the service at the component level.
  selector: 'your-component',
  styleUrls: ['./your.component.scss'],
  templateUrl: './your.component.html',
})
Run Code Online (Sandbox Code Playgroud)