Close all ng-bootstrap modals on logout

Viewed 3207

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.

2 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.

import {NgbModal} from '@ng-bootstrap/ng-bootstrap';

constructor(
    private modalService: NgbModal) { }
LogOut(){this.modalService.dismissAll();}
Related