Reputation: 71
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AuthGuardService implements CanActivate {
constructor() { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean> | Promise<boolean> {
console.log("can activate called");
return true;
}
}
// route
const APP_ROUTES = [{
path: 'login',
CanActivate: [AuthGuardService],
component: login
}
So when login page loads it's not invoking can activate method and printing console. I have created a guard service and added CanActivate property in routes.
Upvotes: 2
Views: 2119
Reputation: 3454
It is because you have an capital C letter in canActivate
in your app-routes.
Make sure you have registered your AuthGuardService
in app.module.ts providers array.
Upvotes: 1