PrimeNG ConfirmDialog中的acceptLabel,acceptVisible不起作用

时间:2018-05-23 06:53:11

标签: angular primeng

我尝试在Angular应用程序的component.ts中自定义PrimeNG ConfirmDialog,但acceptLableacceptVisible属性不起作用。 iconheadermessageaccept()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' */
});

2 个答案:

答案 0 :(得分:1)

您可以直接在HTML中指定它:

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

请参阅StackBlitz

答案 1 :(得分:1)

在PrimeNG 5.2.5之前,acceptLabelrejectLabel无法使用ConfirmationService进行设置:请参阅https://github.com/primefaces/primeng/issues/5090

如果您必须坚持使用版本4.1.1

,则必须在HTML模板中指定它

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