As a seasoned Java developer, I've recently been dabbling in TypeScript.
Let me introduce you to my user object:
export class User
{
id: string;
name: string;
email?: string;
unit: string;
street: string;
postalcode: string;
paymentmode: string;
public isComplete(): boolean
{
if(this.id != null && this.email != null && this.isAddress()){ return true}
else return false;
}
public isAddress(): boolean
{
if(this.street != null && this.postalcode != null){ return true}
else return false;
}
}
Now, onto another block of TypeScript...
var user = new User();
user = this.loginService.getLocalUser();
I was initially hoping to call the isComplete
method on the user object like this:
user.isComplete()
However, to access it, I realized that I need to treat it as a static object instead:
User.isComplete
Here's how I retrieve my local user object:
getLocalUser(): User {
var user = new User();
user = JSON.parse(localStorage.getItem('user'));
return user;
}
Can anyone provide guidance on how to achieve this?