Command does not show Confirmation dialog in Angular PrimeNG

UI Components for Angular
Post Reply
arezki
Posts: 3
Joined: 22 Jun 2021, 16:48

22 Jun 2021, 16:57

I'm implementing a Menu with actions in PrimeNG, the problem is that when I'm executing the action of clicking on menuItem it executes the confirm method, but does not display the Confirmation screen. I've tried to bind the action to an action button. It works.

Here is the code :

Code: Select all

actions: MenuItem[] = [
    {label: 'Activate', icon: 'fas fa-search', command: () => this.active()},
    {label: 'Deactivate', icon: 'far fa-edit', command: () => this.deactivate()},
    {label: 'delete', icon: 'far fa-copy', command: () => this.confirm()}
];
The problem is with the delete command action. Here is the method:

Code: Select all

supprimer(): void {
    this.confirm();
}
Here is the confirm method:

Code: Select all

confirm() {
     this.confirmationService.confirm({
        message: 'etes vous sure de vouloir.....',
        header: 'Confirmation',
        icon: 'pi pi-exclamation-triangle',
        accept: () => {
            this.messages = [{
                severity: 'info', summary: 'confirme',
                detail: 'vous avez accepte....'
            }];
            this.delete();
        },
        reject: () => {
            this.messages = [{
                severity: 'info', summary: 'rejete',
                detail: 'vous avez abandonne'
            }];
        }
    });
    
    
Here is the html :

<ng-template #confirmation >
<div>
<p-confirmDialog></p-confirmDialog>
</div>
</ng-template>

Code: Select all

<p-menu "menu [popup]="true" [model]="actions"></p-menu>

Code: Select all

configurerMenu(menu: Menu, $event: MouseEvent, key: Vue): void {
   this.selectedItem = key;
    this.actions[0].visible = false
   this.actions[1].visible = true
   this.actions[2].visible =true
   this.actions[3].visible = true;
   menu.toggle($event);
}
Last edited by arezki on 28 Jun 2021, 14:19, edited 1 time in total.

PhilHuhn
Posts: 177
Joined: 19 Sep 2018, 02:52
Location: Ann Arbor, Michigan USA
Contact:

24 Jun 2021, 22:22

Hey:
I think you are calling 'this.delete()' directly from the menu. This is the same 'this.delete()' in the 'confirm()' method.

arezki
Posts: 3
Joined: 22 Jun 2021, 16:48

28 Jun 2021, 14:20

it was a mistake ,in the menu i have a confirm() method .
i resolved the probled by adding parameter (event:Evant) in confirm method

thanks alot

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests