Stack Exchange
Can't resolve all parameters for router CanActivate
Im trying to implement authorization guard https://angular.io/docs/ts/latest/guide/router.html#!#can-activate-child-guard
but I get a DI error, I really dont know why I inject my UserService in my module.
My RouteGuard is declared in a Global Module and my UserService too
  @NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  imports: [
   TranslateModule
  ],
  exports: [
    LoadingComponent,
         ],
  declarations: [
    LoadingComponent,

  ],
  entryComponents: [],
  providers: [UserService,RouteGuard]
})
export class GlobalModule { }

Error:
   Uncaught SyntaxError {__zone_symbol__error: Error: Can't resolve all parameters for RouteGuard: ([object Object], ?).
    at SyntaxError.ZoneAwa…, _nativeError: ZoneAwareError}

Code
import { ParentClass } from 'components';
import { Injectable } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { UserService } from '../../modules/user/user.service';
import { User } from 'models';

@Injectable()
export class RouteGuard extends ParentClass implements CanActivate
{
  constructor(
    private router: Router,
    private userService: UserService
  )
  {
    super();
  }

  public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> 
  {
    debugger;

    return this.userService.getUser(this.subId()).toPromise().then(
      (data) =>
      {
        this.setLoggedUser(data);
        if (!this.isAdministrator())
        {
          this.router.navigate(['']);
          return false;
        }
        return true;

      }).catch((err) => { this.error(err); });

  }
}


ok I injected it via Angular Injector  this.userService = this.injector.get(UserService);

What does UserService look like? Does it have the @Injectable() decorator? How do its constructors parameters look like?

Does the error go eway if you remove userService from the parameter list in RouteGuard?
