Search code examples
angularng-bootstrap

stop closing the modal by clicking backdrop or outside the modal


I have used one angular2 ng-bootstrap modal in our code.

I want the modal will not close when I click outside the modal. Currently, the modal is getting closed while clicking outside.

In Angular1 I used to do this by:

[keyboard]="false"
[backdrop]="'static'"

But this time it is not working in Angular2.

Here is my plunker

My Open method is as follows:

  open() {
    const modalRef = this.modalService.open(NgbdModalContent);
    modalRef.componentInstance.name = 'World';
  }

Solution

  • As per the answer of @anshuVersatile, I understand we need to use some modal options.

    Then I create a object of NgbModalOptions and pass it as second parameter of my open method and it works.

    Code is as follows :

    let ngbModalOptions: NgbModalOptions = {
          backdrop : 'static',
          keyboard : false
    };
    console.log(ngbModalOptions);
    const modalRef = this.modalService.open(NgbdModalContent, ngbModalOptions);
    

    Here is the updated plunker.