Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close all ng-bootstrap modals on logout

If the user session times out then he is redirected to the login page.

Problem: If they have a modal open then it remains open when the user is redirected.

What is a good centralized way to close any active modal upon some event (session timeout) using ng-bootstrap that doesn't involve putting code in every modal (or base class) or wrapping the NgbModal service?

I am using Angular 4, Bootstrap 4, and ng-bootstrap.

like image 659
bygrace Avatar asked Nov 16 '17 14:11

bygrace


People also ask

How do I close a bootstrap modal?

You can close modal with the close button or close it programmatically from another component by using this. modalRef. hide() method.

How to Close all the open modals in angular?

Opening & Closing Angular 8 Modal Dialogs open() method with the id of the modal you want to open, e.g. modalService. open('custom-modal-1') . To close a modal call the modalService. close() method with the id of the modal you want to close, e.g. modalService.

How do you close a modal component?

To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.

How do I close a bootstrap modal in angular 10?

Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.


1 Answers

You can import import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; then define this in your logout component's constructor constructor(private modalService: NgbModal){} and finally use this.modalService.dismissAll(); after your logut api call or session expire.

like image 142
Anil kashyap Avatar answered Nov 15 '22 05:11

Anil kashyap