I simply want to retrieve data before the page is loaded in order to be able to display this data.
user.service.ts
export class UserService {
constructor(private httpClient: HttpClient) { }
getUserDetails(username) {
return this.httpClient.get<User[]>(`http://localhost:8080/users/` + username)
.pipe(
map(
userData => {
console.log(userData);
return userData;
}
)
);
}
}
account.component.ts
export class AccountComponent implements OnInit {
username: string;
ngOnInit(): void {
throw new Error('Method not implemented.');
}
constructor(private authenticationService: AuthenticationService, private userService: UserService, private router: Router) {
this.username = sessionStorage.getItem('username');
this.userService.getUserDetails(this.username);
}
logout() {
this.authenticationService.logOut();
}
}