I am encountering an issue with the variable loggined
, which I modify using the logTog()
method. When I call this method, a request is made to a service where the current result is passed to auth.guard
. However, in the console, it displays "undefined". Can anyone help me understand why this is happening and how it can be resolved?
Here is the code for AppComponent:
export class AppComponent implements OnInit {
loggined: boolean = false;
constructor(private galleryService: GalleryService) {}
ngOnInit() {
this.logTog();
}
logTog(): void {
this.loggined = !this.loggined;
this.galleryService.auth(this.loggined);
}
}
Code for the Service:
auth(log:boolean):boolean {
console.log(log);
return log;
}
AuthGuard Code:
export class AuthGuard implements CanActivate, OnInit {
constructor(private galleryService: GalleryService) {}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return this.galleryService.auth();
}
ngOnInit() {
}
}