DI with cyclic dependency with custom HTTP and ConfigService

DI can’t resolve cyclic dependencies. A workaround is to inject the injector and acquire the instance imperatively:

@Injectable()
class ConfigService {
  private http: Http;
  constructor(injector:Injector) {
    setTimeout(() => this.http = injector.get(Http);
  }
}

Leave a Comment