question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dismissing modal with NgbActiveModal only works from within modal-component

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
PEsteves8commented, Mar 16, 2017

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)

7reactions
AvinashDalvi89commented, May 2, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found