While I have experience with AngularJS, delving into Angular2 has proven to be a new challenge for me. Understanding the ropes is still a work in progress.
In my list of files, there's a home.ts
and a home.html
Within my home.ts
, this snippet resides:
@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;
});
}
A user-related data point is stored in localStorage
which I'm assigning to userData
..
However, in my .html
file, an attempt to display information from the userData
variable within a span element hasn't been smooth sailing:
<span id="userName">{{userData.firstName}}</span>
Every time, I run into a flood of errors citing
Cannot read property 'firstName' of undefined
...
I'll appreciate any insights on bridging the gap between the userData
variable and its appearance in my html code. Many thanks!