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
.
You can close modal with the close button or close it programmatically from another component by using this. modalRef. hide() method.
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.
To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.
Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With