Dismissing modal with NgbActiveModal only works from within modal-component
See original GitHub issueI use components which i open within a modal. For example:
const modalRef = this.modalService.open(AbortModalComponent);
Within these modal-components i can inject NgbActiveModal
to close the modal with this.activeModal.dismiss();
. So far so good, but if i inject NgbActiveModal
outside of the modal to close it from somewhere else it doesn’t.
It seems like NgbActiveModal
isn’t a singleton all over the app. But how can i make it one?
In app.module.ts i only import NgbModule.forRoot()
.
Within my sub-modules i import NgbModule
.
Hope i described it good enough. Took me hours to make a Plunker last time 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Angular NgbModal, how to correctly close a modal window?
I use the close method to gracefully close the modal. You could use the dismiss method when you want to return an error...
Read more >Modal - Angular powered Bootstrap
Closes the modal with an optional result value. The NgbModalRef.result promise will be resolved with the provided value. dismiss. dismiss(reason: any) => ...
Read more >Using a bootstrap modal as a dynamic component - Nishu Goel
So let us start by creating an Info modal component which we will render only when we require it on an operation in...
Read more >Angular 12 Bootstrap Modal Popup Example - Pass Data in ...
NgbModal provides from methods. open : Opens a new modal window with the specified content and supplied options. dismissAll : Dismisses all ...
Read more >Angular Close Bootstrap Modal - StackBlitz
div class="container"> · <h2>Modal Close</h2> · <!-- Trigger the modal with a button --> · <button type="button" class="btn btn-info · btn-lg" data-toggle="modal".
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having a way to dismiss modals from the outside would be useful for me too. I have rerouting logic in case the session expires. I occasionally have http requests occurring while modals are open (sometimes within modals). So sometimes, there is an open modal, the session is lost and the user gets rerouted to the login page.
The problem is that when the user gets rerouted the modal is still open, blocking the login page.
I would prefer to allow the service that handles the error handling (rerouting, displaying a warning) to dismiss any open modals, without really caring how they were created in the first place. (Maybe I should approach this differently, but I felt that sharing the use case could stir some more thoughts over the usefulness of allowing this)
Remove NgbActiveModal from provider if you added. Its works for me. example : https://ng-bootstrap.github.io/#/components/modal/examples if you modelcomponent and model content then dont inject NgbActiveModel in provider for component.