Cannot close the Modal through the NgbModalRef

I have a Modal with a form in it, and I want to close it on successful submit.
I save the NgbModalRef as a class property on the open method and im executing this code on submit:

close modal on submit
(had to create the localModalRef because of scope issues)

As soon as it gets to the close() execution the console shouts:

localModalRef.close is not a function

Cant seem to figure out what have i done wrong.

Thanks in advance.

1 possible answer(s) on “Cannot close the Modal through the NgbModalRef

  1. This should be posted on StackOverflow rather than here.

    And you should always post your code as text, rather than as an image, since it makes it easier to read, copy and paste.

    Anyway, you’re not initializing this.modalRef with the NgbModalRef (BTW, TypeScript should warn you about that, if you specify the type of the modalRef property). You’re initializing it with the promise returned by then() on the result property of NgbModalRef.

    The code should be:

    private modalRef: NgbModalRef;
    // ...
    open(content) {
      this.modalRef =;