当我从后台收到特定错误时,是否可以在angular中从拦截器中打开自定义组件(带表单的对话窗口)?我正在努力寻找解决方法,但不能。
假设你的模态组件的名字是MyModalComponent,你想打开它,你的拦截器将是这样的
export class HttpErrorInterceptor implements HttpInterceptor {
constructor(modalService: BsModalService) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
catchError((error: HttpErrorResponse) => {
if(error.status === '404') {
this.modalService.show(MyModalComponent, {});
return throwError(errorMessage);
}
})
)
}
}