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

[Modal Ref] Accessing componentInstance after a modal was closed raises a javascript error #3366

Closed
loicgasser opened this issue Sep 16, 2019 · 0 comments · Fixed by #3367
Closed

Comments

@loicgasser
Copy link
Contributor

loicgasser commented Sep 16, 2019

Bug description:

Accessing componentInstance after a modal was closed raises a javascript error.

Link to minimally-working StackBlitz that reproduces the issue:

demo

Steps to reproduce in the sample.

  1. Click Launch demo modal
  2. Close the modal
  3. Click Raise componentInstance error

Result:

TypeError: Cannot read property 'componentRef' of null

Expected Result:

componentInstance is undefined

The demo demonstrates a simplified version of the problem.
I think this could be useful when you have a NgbModalRef in something like ngOnChanges and you are trying to determine if the modal is open to change its Inputs.

It would allow you to do things like

    if (this._modalRef && this._modalRef.componentInstance) {
      console.log('do something');
    }

which overall would provide more flexibility.

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 8.0.0

ng-bootstrap: 5.1.1

Bootstrap: 4.3.1

@maxokorokov maxokorokov added this to the 5.1.2 milestone Oct 3, 2019
maxokorokov pushed a commit that referenced this issue Oct 3, 2019
`componentInstance` doesn't crash, but returns undefined when _contentRef is null

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

Successfully merging a pull request may close this issue.

2 participants