There is a getUser function in the UserDataService service, in which I call the tokens function, get a token and pass it to another getUser function, from which I get a user by his id.
getUser(id: number) {
return this.sharedDataService.tokens.subscribe((result) => {
return this.userService
.getUser(result, id)
.subscribe((resultService: DataResponse<User>) => {
if (resultService.status === StatusType.SUCCESSFUL) {
return resultService.data;
} else {
return null;
}
});
});
}
export interface User{
id: number;
name: string;
}
How do I get a User object when calling this function? This code will not work.
let user = this.userDataService.getUser(1);
How to correctly pass objects from such functions? You can transmit by event, but in this case it is not very convenient. Maybe you can subscribe to the get User function?