I've used AngularJS a lot in the past, but Angular2 is a whole new world for me.. and I've not quite gotten it down.
I have a home.ts and a home.html
Inside my home.ts I have this:
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
userData:any;
constructor(
public navCtrl: NavController,
private storage: Storage,
private database: AngularFireDatabase) {
this.storage.get('user').then((result) => {
this.userData = result;
});
}
I have a localstorage variable for the user, and I'm assigning it to userData..
Inside my .html file, I have a span that I'd like to populate with info from the userData variable... I thought it would be as easy as doing this:
<span id="userName">{{userData.firstName}}</span>
but I just get a ton of errors Cannot read property 'firstName' of undefined...
How can I get the userData variable into my html? Thanks!
storage.getto thengOnIntlifecycle hook. Why? This will allow for re-fetching of your localStorage data everytime this component gets displayed to screen instead of only once at the beginning of the application spin up time.