Stop and allow current event propagation on Angular 2 primeng confirmdialog

UI Components for Angular
Post Reply
niladri27dutta
Posts: 2
Joined: 08 Jun 2017, 14:33

08 Jun 2017, 14:55

I am using primeng confirmdialog to show a confirmation modal(p-confirmDialog) on "beforeunload" event if there are unsaved changes. Below is the code for the angular 2 component

Code: Select all

@Component({

//selector and other properties

 host: {
    '(window:resize)': 'onResize($event)',
    '(window:beforeunload)': 'confirmNavigation($event)'

  }

})
This component is loaded dynamically within a primeng modal.I have included the selector in the html template for the component.

Code: Select all

<p-confirmDialog class="confirmdialog" header="Confirmation" appendTo="body" icon="fa fa-question-circle" width="425"></p-confirmDialog>
Here is the confirmNavigation function

Code: Select all

confirmNavigation(event:any) {
        var isEditableMode = this.form.isDirty; // check if the form is dirty
        if (isEditableMode == true) {
        this.confirmationService.confirm({
          message: 'Do you want to leave the page?',
          accept: () => {
           //Need to allow the current event to continue if the user clicks on 'Yes'
          },
     reject: () => {
      return false; // prevent the current event, return false is not working

         }
      });
   }
 }
I am able to see the confirmation modal before the page is reloaded, tab is closed,browser closed etc.But I want to allow the current event to continue(for example page reload etc)if the user clicks on "Yes" under "accept" property. How to handle the event here inside the arrow function?For reject I want to stop the event propagation.

Can anybody help?

niladri27dutta
Posts: 2
Joined: 08 Jun 2017, 14:33

09 Jun 2017, 09:18

has anybody faced this scenario?

sivanandan
Posts: 8
Joined: 03 Nov 2016, 11:00

14 Dec 2017, 16:58

I have used below code but still no luck
export class AppComponent{constructor(private confirmationService:ConfirmationService){}
@HostListener('window:beforeunload', ['$event']) public onWindowScroll( $event:any)
{
return new Promise((observer) => {this.confirmationService.confirm({
message:"All the information would be lost, are you sure you want to move out of the screen?", accept: () => { $event.returnValue ="";
observer(true);
},
reject: () => {

observer(false);
}
});
});
}
}

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 28 guests