Interceptor not intercepting http requests (Angular 6)

前端 未结 5 832
自闭症患者
自闭症患者 2021-01-01 11:10

I\'m in the proces of adding an interceptor to my angular 6 project. To make calls to my API, I need to add a bearer token to all calls. Unfortunately the interceptor does n

5条回答
  •  醉梦人生
    2021-01-01 11:55

    If you have a providers array for a module then you have to define the HTTP_INTERCEPTORS too for that module then only it will intercept the requests under that module.

    e.g:

    providers: [ 
    // singleton services
    PasswordVerifyService,
    { provide: HTTP_INTERCEPTORS, useClass: AppInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptorService, multi: true }
    ]
    

提交回复
热议问题