我尝试在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' */
});
答案 0 :(得分:1)
您可以直接在HTML中指定它:
<p-confirmDialog acceptLabel="Yes, Sure!" rejectLabel="No, I Don't!"></p-confirmDialog>
请参阅StackBlitz
答案 1 :(得分:1)
在PrimeNG 5.2.5之前,acceptLabel
和rejectLabel
无法使用ConfirmationService
进行设置:请参阅https://github.com/primefaces/primeng/issues/5090
如果您必须坚持使用版本4.1.1
,则必须在HTML模板中指定它