Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catching dismiss event ngx-bootstrap modal [closed]

I'm using angular 6 and ngx-bootstrap 3.0.1

I display a modal and I want to be able to show a discard/cancel confirmation when the user try to close the modal after updating the form.

I have no issue when the user use my custom close button, but I don't know how to call my closing function when he use the backdrop-click outside the modal.

How can I handle the backdrop-click cleanly to be able to display my confirmation message?

like image 683
Arthur Saint-Genis Avatar asked Nov 06 '22 20:11

Arthur Saint-Genis


1 Answers

Open your modal with options

this.bsModalRef = this.modalService.show(ExampleModal, {
  ignoreBackdropClick: true,
  keyboard: false
});

In ExampleModal place this code

ngOnInit(): void {
     document.documentElement.addEventListener('click',  this.hideIfIsBackdropClick.bind(this)); 
}

hideIfIsBackdropClick(event: any): void {
     if (event.target.classList.contains('modal')) {
        this.hide();
     }
}

hide(): void {
   if (anyBooleanHere) {
      this.bsModalRef.hide();
   }
}
like image 197
Remigiusz Avatar answered Nov 15 '22 06:11

Remigiusz