这是我的用户对象:
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 } }
还有另外一个打字稿
var user = new User(); user = this.loginService.getLocalUser();
我假设localStorage被解析给用户!
我无法以这种方式访问isComplete方法
user.isComplete()
相反,我需要使用它作为静态对象
User.isComplete
我的getLocaluser:
getLocalUser(): User { var user = new User(); user = JSON.parse(localStorage.getItem('user')); return user; }
我该如何实现?