I have a component called login that when login completes the data of the user object, I need to get the "charge" field of this object and receive it in another component.
I've tried:
login.component.ts:
public usuario: Usuario = new Usuario()
fazerLogin(email: string, password: string): void{
//função que faz o login...
this.enviaCargo(this.usuario.cargo)
}
enviaCargo(cargo: string): void{ //aqui eu envio o valor para uma função do serviço.
this.authService.setCargo(cargo);
}
auth.service.ts:
public cargo: string;
setCargo(cargo: string){
this.cargo = cargo;
}
getCargo(){
return this.cargo;
}
And then, in the component I want this given, I do:
private cargo: string;
ngOnInit() {
if (typeof this.cargo === 'undefined' || !this.cargo) {
this.cargo = this.loginService.getCargo();
}
}
When the component receives the job, however, when I reload the page, I lose this data because it is only populated when I log in.