从 HttpInterceptor 显示模式对话框

Mun*_*war 2 javascript typescript angular-material angular httpinterceptor

@Injectable()
export class MyInterceptor implements HttpInterceptor
{
    intercept(req : HttpRequest<any>, next : HttpHandler) : Observable<HttpEvent<any>>
    {
//show a modal dialog to hold the request until user respond/close the dialog
        if(ShowModalDialog())
        {
            return next.handle(req);
        }
        else
        {
//route to login
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图显示一个有角度的材质对话框,但它不会阻止请求,并且会继续执行下一行。

我需要知道如何在出现请求错误响应时从拦截器显示模式对话框,向用户显示一些选项并在对话框关闭后恢复执行。

是否可以通过此类对话框停止/保留请求?

Pie*_*Duc 5

您可以使用角度材质对话框来执行此操作:

@Injectable()
export class MyInterceptor implements HttpInterceptor {
  constructor(private dialog: MatDialog, private router: Router) {}
  
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    if(ShowModalDialog()) {
      return this.dialog.open(DialogModalComponent).afterClosed().pipe(
        concatMap(() => next.handle(req))
      );
    } else {
      return next.handle(req);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)