Bug description:
When trying to implement the Modal using a component like the example here “Components as content”
https://ng-bootstrap.github.io/#/components/modal/examples
It works like so.
However I want to also use that component outside of a modal, but when I try to access that component using its selector I get the error:
“Unhandled Promise rejection: No provider for NgbActiveModal! ; Zone: ; Task: Promise.then ; Value: Error: No provider for NgbActiveModal!”
Link to minimally-working plunker that reproduces the issue:
https://plnkr.co/edit/hZMD3vWphJEm7dwLxVEU?p=preview
You’ll see in the console as soon as the app loads, it will throw the error.
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 4.2.4
ng-bootstrap: 1.0.0-beta.1
Bootstrap: 4.0.0-alpha.6
This works as designed – you can’t access
NgbActiveModal
outside of the modal context: theNgbActiveModal
injectable is provided by the modal service.Not sure what you exact use-case is so hard to suggest anything…
So if I want to use a component inside a modal and also outside of a modal, how would I go about doing that?
try to provide
NgbActiveModal
on app.module@oslanier With that you can get an instance of
NgbActiveModal
but you still not able to close the current modal.As @pkozlowski-opensource said, the service is inject only in the instance of the modal is being opened