我有一个带有HttpInterceptor的核心模块用于授权处理,我在AppModule中包含了这个模块,这样使用HttpClient的所有其他模块都使用这个拦截器. @NgModule({ imports: [], declarations: [], providers: [ { provid
@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拦截.