HttpInterceptor->Service->HttpClient Cyclic Dependency

后端 未结 3 1526
借酒劲吻你
借酒劲吻你 2020-12-10 06:09

So I have my authentication service, AuthService, that basically has two methods, one that gets a new token from the server, given a username and a password

3条回答
  •  [愿得一人]
    2020-12-10 07:01

    I was running into the same or a similar issue using Angular 6.1.10. I simply instantiated HttpClient myself inside the service that need to be injected into an HttpInterceptor:

    @Injectable()
    export class AuthService {
    
      private http: HttpClient;
    
      constructor(httpBackend: HttpBackend) {
        this.http = new HttpClient(httpBackend);    
      }
    }
    

    That broke the infinite loop issue in my case.

提交回复
热议问题