title: angular guard-service inject service
body: <p>I need to inject a service in a guard. This guard checks if the user was invited, when yes, he can access the route.</p>
  
  <p>To check this condition, I need to call a service which fetches this information from the db.</p>
  
  <p>I have a cyclical dependency error, I understand that we shouldn't inject services in Guards, but in this case, I need to do it:</p>
  
  <pre><code>  providers: [AuthService, HackService, HacksStorageService, AuthGuard, EmailGuard],
  </code></pre>
  
  <p>And the guard:</p>
  
  <pre><code>import { ActivatedRouteSnapshot, RouterStateSnapshot, CanActivate } from "../../../node_modules/@angular/router";
  import { HacksStorageService } from "../shared/hacks-storage.service";
  
  export class EmailGuard implements CanActivate {
  
    constructor(
      private hacksStorageService: HacksStorageService,
    ) {}
  
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      this.hacksStorageService.fetchHack();
      // check if user was invited. should be in the participants array
      return true;
    }
  }
  </code></pre>
  
  <p>I am pretty confused. Usually I used guards to see if user is logged in or not, so I usually imported stuff from firebase, not from my own services, so not cyclical dependencies.</p>
  
  <p>Now I want to check if a condition happens, based on my own data. How can I inject my own data in the EmailGuard, if I am not allowed to inject services because of the cyclical dependency?</p>
  
  <p>Thanks.</p>