Angular 5 Http Interceptors error when injecting service

后端 未结 8 925
北海茫月
北海茫月 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:19

    For me @Benjineer answar helped to provide as a dependency in app.module.ts the required sercvice.

    Although what is interensting, in the order you add as a dependency in app.module.ts you get it in the constructor of the service.

    For Example: in the app module you provide in the order of AuthService, ErroMsgService

    deps: [AuthService, ErrorMsgService]
    

    in the HttpInterceptor constructor you have to create them in the same order

     constructor(
        private authService: AuthService,
        private errorService: ErrorMsgService
        ) {}
    

提交回复
热议问题