首页 > 解决方案 > PrimeNG ConfirmDialog 中的 acceptLabel、acceptVisible 不起作用

问题描述

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

PrimeNG 版本:4.1.1

以下是代码:

组件.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>

组件.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' */
});

标签: angularprimeng

解决方案


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

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

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


推荐阅读