Search code examples
angularrouterguard

Angular Router Guard Error Can't resolve all parameters for


Hello I'm trying to create a Router Guard:

My auth.guard.ts file:

import { CanActivate,
         Router,
         ActivatedRouteSnapshot,
         RouterStateSnapshot } from '@angular/router';

export class AuthGuard implements CanActivate{
  constructor(private router: Router) { }
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){
    return true; // just for tests gonna change that later
  }
}

I import it in app.module.ts into providers.

The problem is that I now get this Error:

 Can't resolve all parameters for AuthGuard: (?).

What is wrong? How can I fix that? I mean im not even using the Guard in my APP_ROUTES yet.


Solution

  • You are missing the @Injectable() decorator:

    @Injectable()
    export class AuthGuard implements CanActivate { ...