I work on Angular2 web application. I created a simple class in typescript:
export class User {
firstName: string;
lastName: string;
nominative() : string {
return this.lastName + " " + this.firstName;
}
}
When i call nominative
on object of type User
I receive this error: Error in :0:0 caused by: user.nominative is not a function
.
I call the function in my AppComponent
class:
export class AppComponent implements OnInit {
name: string = "";
ngOnInit() : void {
let user = JSON.parse(sessionStorage.getItem("User")) as User;
if (user) {
this.name = user.nominative();
}
}
}
I already tried to use lambda expression in this way:
nominative = () : string => { ... }
But nothing change. The problem is only in this class, so what am I doing wrong?