Ionic storage undefined


#1

I have this code:

[...]
<ion-col col-4>
  <h1> {{ employee.name }} </h1>
</ion-col>
<ion-col col-6>
  {{ employee.avatar_urls[96] }}
</ion-col>
[...]

and this code:

[...]
constructor(...) {
    this.storage.get("userLogged").then(res => {
      this.employee = res
      console.log(this.employee)
    });
  }
[...]

In the console.log() the employee appear with all the fields, when the DOM try to loading the page it return “cannot read property name of undefined”… I can’t understand, if in .log() it appears, why not in the DOM?


#2

promises are asynchronous. view loaded before data is fetched. use ? in the html. {{ employee?.name }}.


#3

It works!! What change the “?” ???


#4

safe navigation operator https://angular.io/guide/template-syntax#safe-navigation-operator