this part is the component where I am receiving a json. it contains the number.
public loginA(){
this.loginService.login(this.usuario).subscribe(
datos => {return datos['id']}
);
}
The value that data ['id'] shows me there can be 1 or -1 but I can't return it to this guard
export class LoginGuard implements CanActivate {
constructor(private loginComponent:LoginComponent){}
canActivate(){
if(this.loginComponent.loginA()>0){
return true;
}else{
return false;
}
}
}
here it gives error this.loginComponent.loginA() because it is not returning anything
The error can occur here
datos['id']
since it is an array you have to access the index of the array like this
datos[indice].propiedad
For you it would be something like this
datos[0].id
Subscriptions to observables do not return anything, they are used in another way. I show you an example below:
Assuming that the component that contains the method
loginA
is called "LoginComponent", the following remains:Hope this can help you