Angular 5 Http Interceptors error when injecting service

后端 未结 8 869
北海茫月
北海茫月 2021-02-05 05:43

I am receiving the following strange dependency injection behavior when using custom HttpInterceptors in angular 5+.

The following simplified code works fine:

         


        
相关标签:
8条回答
  • 2021-02-05 06:26

    For this issue, make sure that the service which you are injecting in Http interceptor needs to be added in providers along with the HTTP_INTERCEPTORS in the module.

    providers: [ AuthService,
        {
          provide: HTTP_INTERCEPTORS,
          useClass: HttpConfigInterceptor,
          multi: true
        }
    ]
    
    0 讨论(0)
  • 2021-02-05 06:31

    You need to add the auth service as a dependency of the interceptor.

    providers: [ 
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpConfigInterceptor,
      multi: true,
      deps: [AuthService]
    }
    
    0 讨论(0)
提交回复
热议问题