How to programmatically close ng-bootstrap modal?

To expound upon pkozlowski.opensource’s response, the way I actually got the reference to the NgbModalRef class was by modifying what is in his plunker on the this.modalService.open as follows:

this.modalReference = this.modalService.open(content);
this.modalReference.result.then((result) => {
  this.closeResult = `Closed with: ${result}`;
}, (reason) => {
  this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});

Then I was able to call:

this.modalReference.close();

Which worked like a charm. Oh, and don’t forget to put define modalReference at the top of the class:

modalReference: any;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)