Show modal dialog from HttpInterceptor


export class MyInterceptor implements HttpInterceptor {
    req: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {

    //show a modal dialog to hold the request until user respond/close the dialog
       return next.handle(req);
       route to login

I have tried to show a angular material dialog but it does not block the request and continue execute to next line.

How to show a modal dialog from intercepter on finding the request is errored out, show user some options and resume execution after dialog is closed.

Is it possible to stop/hold a request with such dialog?


You can do this with an angular material dialog:

export class MyInterceptor implements HttpInterceptor {
  constructor(private dialog: MatDialog, private router: Router) {}
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    if(ShowModalDialog()) {
        concatMap(() => next.handle(req))
    } else {
      return next.handle(req);

Answered By – Poul Kruijt

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.