I have a basic Angular application that retrieves data from a Spring-Boot backend.
export class UserDto {
constructor(
public login: string,
public password: string,
) {
}
}
export class AuthService {
private url = '....';
getUser() {
return this.http.get<UserDto[]>(this.url);
}
}
In my component, I have a function that creates a map of values:
constructor(private auth: AuthService){}
private getMapOfUsers() {
const userMap: Map<string, string> = new Map<string, string>();
this.auth.getUser().subscribe(res => {
res.map(item => {
userMap.set(item.login, item.password);
}
);
});
return userMap;
}
When I call:
getLoginData() {
console.log(this.getMapOfUsers());
}
The console displays the result:
https://i.sstatic.net/X10OJ.png
The login from UserDto appears crossed out in red
Even though I see objects in "Entries", the size of the map is displayed as 0. I am unable to retrieve the actual size or content of the map.
getLoginData() {
console.log(this.getMapOfUsers().size); // result = 0
}
How can I resolve this issue so that I can successfully map these objects and access the password using the login as the key?