显示来自 HttpInterceptor 的模态对话框
Show modal dialog from 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
}
}
我试图显示一个 angular material 对话框,但它不会阻止请求并继续执行到下一行。
如何在发现请求出错时显示来自拦截器的模态对话框,向用户显示一些选项并在对话框关闭后恢复执行。
是否可以stop/hold请求这样的对话框?
您可以使用 angular material 对话框执行此操作:
@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);
}
}
}
@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
}
}
我试图显示一个 angular material 对话框,但它不会阻止请求并继续执行到下一行。
如何在发现请求出错时显示来自拦截器的模态对话框,向用户显示一些选项并在对话框关闭后恢复执行。
是否可以stop/hold请求这样的对话框?
您可以使用 angular material 对话框执行此操作:
@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);
}
}
}