I have this mapping:
User *----------------------------1 Role
From the list of users, I go to consult one user from this list.
To get some informations about that selected user, I need to use localSorage
to get an object from inside subscribe to outside subscribe.
Bellow is the method:
this.userService.getAllRolesOfActualUser(user.id).subscribe(listRoles =>
{
let roles:Array<Role> = [];
if (listRoles)
{
listRoles.forEach((role) =>
{
roles.push(new Role(role.id, role.name, role.selected));
});
}
sessionStorage.removeItem("roles");
sessionStorage.setItem("roles", JSON.stringify(roles));
console.log("1. Inside Subscribe- " + user.id + "--------------: " +
sessionStorage.getItem("roles"));
});
console.log("2. Outside Subscribe- " + user.id + "--------------: " + sessionStorage.getItem("roles"));
On user.service.ts, I have:
getAllRolesOfActualUser(id: number): Observable<any>
{
return this.http.get(`${this.baseUrl}/users/roles/${id}`);
}
My problem is that usually I got the value of the previous consulted user not the actual user a described by this screenshot:
Could you please help me solving that issue ?!. Big thanks.