I have a simple component with a property userFirstName
.
Now I just want to display this property. I have made a simple binding, and I initialize the userFirstName
in the constructor but it works only when there it is the first command!
So this works fine: and it shows the "User Name" text.
this.userFirstName = "User Name";
this.loggedIn = localStorage.getItem("currentUser")!=null;
var currentUser = localStorage.getItem('currentUser');
let user:User = JSON.parse(currentUser) ;
this.userFirstName = localStorage.getItem('currentUser');
Now if I put this.userFirstName = "User Name";
at the last, it doesn't work.
So this doesn't work and it shows empty string!
this.loggedIn = localStorage.getItem("currentUser")!=null;
var currentUser = localStorage.getItem('currentUser');
let user:User = JSON.parse(currentUser) ;
this.userFirstName = localStorage.getItem('currentUser');
this.userFirstName = "User Name";
Here is the corresponding html:
<div>
<a >Hello {{userFirstName}} ! </a>
//some content
</div>