I implement a role guard in my Angular 11 project, when i was coding i got this doubt:
Why when inject ActivatedRoute in constructor i didn't get route data?
code:
constructor(private route: ActivatedRoute) {}
canActivate(): boolean {
this.route.data.subscribe(res => console.log(res));
return true;
}
console:
{}
But, if i pass the ActivatedRoute by params through canActivate(), i get them
code:
constructor() {}
canActivate(route: ActivatedRoute): boolean {
console.log(route.data);
return true;
}
console:
{role: Array(2)}
why happen this?