1 year ago
#387770
kintela
I'm loosing values in parameter service when I refresh pages in Angular
I'm using msal angular library to log users in my app.
Once the user has logged I save the value in my parameter service to share it with the rest of the components.
parameter.service.ts
@Injectable()
export class ParameterService {
....
empleado:Empleado;
}
home.component.ts
this.dataService.getEmpleadoByMail(this.usuario.username)
.subscribe(
data => {
this.parameterService.empleado = data;
this.router.navigate(['/planificador', data.empId, 'proyectos']);
}
, err => console.error(err)
, () => { }
);
Once the employee associated with the login has been obtained, the projects that can be planned are displayed
If at this moment I simply refresh this same page I see that the employee property of parameterService is undefined
export class SidenavComponent implements OnInit {
....
get empleadoId(): number {
return this.parameterService.empleadoId;
}
constructor(private parameterService: ParameterService){}
ngOnInit(): void {
if (this.empleado == undefined) {
}
I don't know if this is the correct behavior but then it doesn't make sense to use a service injected in your components to share values if you lose them in a refresh right?
Any idea, please?
Thanks
angular
angular-services
angular-components
0 Answers
Your Answer