我有一个核心模块,带有一个用于授权处理的HttpInterceptor,我将这个模块包括在AppModule中,以这种方式,使用HttpClient的所有其他模块都在使用这个interceptor.

@NgModule({
  imports: [],
  declarations: [],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: AuthInterceptor,
      multi: true,
    },
  ]
})
export class CoreModule { }

如何使模块绕过默认的拦截器?

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: components,
  providers: [CustomService],
  exports: components,
})
export class ModuleWithoutInterceptorModule { }

推荐答案

您可以使用HttpBackend.

例子:

import { HttpClient, ..., HttpBackend } from '@angular/common/http';

@Injectable()
export class TestService {

  private httpClient: HttpClient;

  constructor( handler: HttpBackend) { 
     this.httpClient = new HttpClient(handler);
  }
....

这样,AuthInterceptor就不会拦截服务.

Angular相关问答推荐

如何在Angular应用程序部署中安全地管理环境变量

Angular 信号效果,try 重置表单并获取在计算或效果中不允许写入信号"

CDK虚拟滚动由于组件具有注入属性而在滚动时看到错误的值

角material 17 -如何从Style.scss中的主题中获取原色

NG-Zorro Datepicker 手动输入掩码不起作用

Angular 路由中的模块构建失败

Angular 9表单构建器 - 日期验证器问题

在生产模式下使用带Angular 的 livekit

Angular 升级后 RXJS SwitchMap 无法与解析器一起正常工作

如何将模块导入独立指令

Angular 15:在范围内提供相同标记时附加到提供的值

Angular 从 13.3.8 恢复到 13.3.7

Angular 2 - 组件内的 formControlName

如何在 Angular 2 中创建可重用的动画

如何手动延迟加载模块?

@angular/platform-b​​rowser 与 @angular/platform-b​​rowser-dynamic

Lint 错误:实现生命周期挂钩接口

Angular2 - 从外部验证和提交表单

Angular单元测试输入值

如何在 Angular 中使用带有 SASS 的 Bootstrap 4