Angular PrimeNg如何链接确认对话框
Angular PrimeNg how to chain confirmdialog
我正在使用 primeng ConfirmationService 来显示确认对话框。确认第一个对话框后,我想根据条件显示另一个对话框。但它不起作用。这是我的代码。谁能帮我解决这个问题?
this.confirmDialog.confirm({
header: 'Begin',
message: 'Are you sure you would like to start?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
if(this.currentUserId !== workflow.assignedToId) {
this.confirmDialog.confirm({
header: 'Reassign',
message: 'reassign it to yourself?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
console.log('accept 2 diffeent user');
},
reject: () => {
console.log('reject 2 diffeent user');
}
})
} else {
console.log('accept 1 same user');
}
},
reject: () => {
console.log('reject 1 same user');
}
})
您需要创建 2 个具有不同键值的 confirmDialog:
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm1"></p-confirmDialog>
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm2" ></p-confirmDialog>
并且您需要像这样将密钥添加到 confirmationService 函数中:
confirm1() {
this.confirmationService.confirm({
message: 'Are you sure that you want to proceed?',
header: 'Confirmation',
icon: 'pi pi-exclamation-triangle',
key: 'confirm1',
accept: () => {
this.confirm2();
this.msgs = [
{
severity: 'info',
summary: 'Confirmed',
detail: 'You have accepted',
},
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
confirm2() {
this.confirmationService.confirm({
message: 'Do you want to delete this record?',
header: 'Delete Confirmation',
icon: 'pi pi-info-circle',
key: 'confirm2',
accept: () => {
this.msgs = [
{ severity: 'info', summary: 'Confirmed', detail: 'Record deleted' },
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
你可以在 Stackblitz 上看到一个例子
https://stackblitz.com/edit/primeng-confirmdialog-demo-v1x93e?file=src/app/app.component.ts
我正在使用 primeng ConfirmationService 来显示确认对话框。确认第一个对话框后,我想根据条件显示另一个对话框。但它不起作用。这是我的代码。谁能帮我解决这个问题?
this.confirmDialog.confirm({
header: 'Begin',
message: 'Are you sure you would like to start?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
if(this.currentUserId !== workflow.assignedToId) {
this.confirmDialog.confirm({
header: 'Reassign',
message: 'reassign it to yourself?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
console.log('accept 2 diffeent user');
},
reject: () => {
console.log('reject 2 diffeent user');
}
})
} else {
console.log('accept 1 same user');
}
},
reject: () => {
console.log('reject 1 same user');
}
})
您需要创建 2 个具有不同键值的 confirmDialog:
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm1"></p-confirmDialog>
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm2" ></p-confirmDialog>
并且您需要像这样将密钥添加到 confirmationService 函数中:
confirm1() {
this.confirmationService.confirm({
message: 'Are you sure that you want to proceed?',
header: 'Confirmation',
icon: 'pi pi-exclamation-triangle',
key: 'confirm1',
accept: () => {
this.confirm2();
this.msgs = [
{
severity: 'info',
summary: 'Confirmed',
detail: 'You have accepted',
},
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
confirm2() {
this.confirmationService.confirm({
message: 'Do you want to delete this record?',
header: 'Delete Confirmation',
icon: 'pi pi-info-circle',
key: 'confirm2',
accept: () => {
this.msgs = [
{ severity: 'info', summary: 'Confirmed', detail: 'Record deleted' },
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
你可以在 Stackblitz 上看到一个例子 https://stackblitz.com/edit/primeng-confirmdialog-demo-v1x93e?file=src/app/app.component.ts