Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot close the Modal through the NgbModalRef #722

Closed
kesemdavid opened this issue Sep 11, 2016 · 3 comments
Closed

Cannot close the Modal through the NgbModalRef #722

kesemdavid opened this issue Sep 11, 2016 · 3 comments

Comments

@kesemdavid
Copy link

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.

@jnizet
Copy link
Member

jnizet commented Sep 11, 2016

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 = this.modalService.open(content);
  this.modalRef.result.then(...);
}

@jnizet jnizet closed this as completed Sep 11, 2016
@kesemdavid
Copy link
Author

You're absolutely right, sorry for posting here, thanks a lot

@ishraqh
Copy link

ishraqh commented Jun 17, 2020

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 = this.modalService.open(content);
  this.modalRef.result.then(...);
}

you saved my day. Thank you so much dude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants