I have a typescript class:
export class User {
id: number;
userName: string;
knownAs: string;
age: number;
gender: string;
created: Date;
lastActive: Date;
photoUrl: string;
city: string;
country: string;
surname: string;
givenname: string;
get fullName(): string {
return `${this.givenname} ${this.surname}`;
}
sayHello() {
console.log(`Hello, my name is ${this.surname} ${this.givenname}!`);
}
}
I have a Service function:
user: User;
this.userService.getUser(this.loggedUser.nameid).subscribe((user: User) => {
this.user = user;
this.user.givenname = this.loggedUser.given_name;
this.user.surname = this.loggedUser.family_name;
console.log(this.user.fullName);
this.user.sayHello();
});
the result in the console: console.log(this.user.fullName) = undefined this.user.sayHello(); = ERROR TypeError: Object doesn't support property or method 'sayHello'
After when I get back the user data from the server, how I can reach property and function which I've defined in the user class?
userresult on the subscribe function actually an instance of theUserclass?getUser()code to understand the error.map