ngx-bootstrap icon indicating copy to clipboard operation
ngx-bootstrap copied to clipboard

Modal EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'parentInjector' of undefined

Open theunreal opened this issue 10 years ago • 5 comments

When trying to open a modal in my component, I get the following error:

EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'parentInjector' of undefined

Been trying the exact same code as the demo:

<button class="btn btn-primary" (click)="lgModal.show()">Large modal</button>
<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title">Large modal</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
    </div>
  </div>
</div>

What could have gone wrong?

theunreal avatar Jun 12 '16 16:06 theunreal

@theunreal Did you remember to include the viewContainerRef:ViewContainerRef into your application root component? Link Modals Hack

DawidvanGraan avatar Jun 12 '16 17:06 DawidvanGraan

Yes @DawidvanGraan , I noticed that I get this error only inside specific component, and this component is inside a

. maybe it causes the error..

theunreal avatar Jun 13 '16 14:06 theunreal

I'm getting this error and couldn't solve it. wats the fix?

priteshacharya avatar Jul 18 '16 23:07 priteshacharya

@priteshacharya read the important notes in doc http://valor-software.com/ng2-bootstrap/#/modals

valorkin avatar Jul 19 '16 06:07 valorkin

Including the ViewContainerRef in the root application's constructor did the trick for me. Thanks!

timvl avatar Aug 04 '16 13:08 timvl