【问题标题】:acceptLabel, acceptVisible in PrimeNG ConfirmDialog are not workingPrimeNG ConfirmDialog 中的 acceptLabel、acceptVisible 不起作用
【发布时间】:2018-11-02 01:06:48
【问题描述】:

我试图在我的 Angular 应用程序的 component.ts 中自定义 PrimeNG ConfirmDialog,但 acceptLable、acceptVisible 属性不起作用。 icon、header、message、accept()、reject() 等都工作正常。这有什么线索吗?

PrimeNG 版本:4.1.1

以下是代码:

component.html:

<p-confirmDialog closable="false" #cd>
    <p-footer>
        <button type="button" (click)="cd.accept()"></button>
        <button type="button" (click)="cd.reject()"></button>
    <p-footer>
</p-confirmDialog>

component.ts:

import {ConfirmationService} from 'primeng/primeng';

@Component({
    ..
    providers: [ConfirmationService]
})

constructor(private confirmService: ConfirmationService){
    this.notAllowedToLeave = true;    /* Based upon this variable the confirmation dialog will display the Accept button i.e. "Yes, Sure!" */
    ...
}

this.confirmService.confirm({
    message: 'Are you sure you want to exit?',
    header: 'Warning: Quit Application',
    icon: 'fa fa-exclamation-triangle',
    accept: () => { /* My accept actions */ },
    reject: () => { /* My reject actions */ },
    acceptVisible: this.notAllowedToLeave ? false : true,    /* No effect */
    acceptLabel: 'Yes, Sure!',      /* Giving Error:  'acceptLabel' does not exist in type 'Confirmation' */
    rejectLabel: 'No, I Don't!'     /* Giving Error:  'rejectLabel' does not exist in type 'Confirmation' */
});

【问题讨论】:

  • 我认为您通过在模板文件中写入 标记来覆盖它,只需从模板中删除 标记并尝试运行。
  • 是的,你是对的。它被覆盖了。但正如@splash 下面所说,PrimeNG 版本是另一个原因。

标签: angular primeng


【解决方案1】:

在 PrimeNG 5.2.5 之前,acceptLabel 和 rejectLabel 属性无法使用 ConfirmationService 设置:请参阅 https://github.com/primefaces/primeng/issues/5090

如果您必须坚持使用版本 4.1.1,则必须在 HTML 模板中指定它

https://stackblitz.com/edit/primeng411-confirmation-test

【讨论】:

  • 是的!它的版本问题。但不幸的是,由于项目限制,我无法更改版本,而是我将使用您的第二个解决方案,即在 HTML 中指定内容
【解决方案2】:

您可以直接在 HTML 中指定:

<p-confirmDialog acceptLabel="Yes, Sure!" rejectLabel="No, I Don't!"></p-confirmDialog>

见StackBlitz

【讨论】:

  • 是的,这很有帮助。对于我的 PrimeNG 版本,我将采用您的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-22
  • 2018-10-05
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多