Variable is not printing on screen. (See Image) - I'm a newbie


#1

Good afternoon,

I’m having trouble displaying the return of an object.

It’s only working on first-level returns. (As shown in the picture).

What am I doing wrong?
I get the error: “TypeError: Cannot rea property ‘total’ of undefined at Object.eval [asupdateRendere]…”

I did not understand and I can not solve


Sorry my english :confused:


#2

Your English is fine. Posting text as images instead of text is not.

That being said, when you are initializing resultado, you must give it at least {transactions: {}} to avoid this problem.


#3

It worked!!
Thanks :slight_smile:


#4

Hello, I have managed to solve the problem, doing this …

Is there any easier way to do it?

Will I ever NEED to declare the keys?

TS

export class ResumoPage {
  loader;
  info = 'teste';
  infoRei = new Array();
  resultado = { transactions: {},
                metrics: {
                  sales: {},
                  claims: {},
                  delayed_handling_time: {},
                }
              };

  constructor(
    public navCtrl: NavController, 
    public navParams: NavParams,
    public MercadoLivreProvider: MercadoLivreProvider,
    public loadingController: LoadingController,
    platform: Platform) {
        this.loader = this.loadingController.create({
            content: "Buscando Usuários"
        });
  }

  ionViewDidLoad() {
    let eu = this;
    this.MercadoLivreProvider.getResumo().then( retorno => {  
      eu.resultado = (retorno as any);
      //console.log(eu.resultado.transactions);
      console.log(JSON.stringify(eu.resultado.metrics, null, 4));
    });
  }

}

HTML

<ion-content padding>
    <ion-grid class="reputacao">
      <ion-row class="a40" id="level{{ resultado.level_id }}">
        <ion-col col-1></ion-col>
        <ion-col col-2 class="r1"></ion-col>
        <ion-col col-2 class="r2"></ion-col>
        <ion-col col-2 class="r3"></ion-col>
        <ion-col col-2 class="r4"></ion-col>
        <ion-col col-2 class="r5"></ion-col>
        <ion-col col-1></ion-col>
      </ion-row>
    </ion-grid>
    <ion-grid>
        <ion-row>
          <ion-col col-3>
            <ion-icon name="cart"></ion-icon><br>
            {{ resultado.transactions.total }}
          </ion-col>
          <ion-col col-9>
              <ion-row>
                  <ion-col col-12>{{ resultado.transactions.completed }}</ion-col>
              </ion-row>
              <ion-row>
                  <ion-col col-12>{{ resultado.transactions.canceled }}</ion-col>
              </ion-row>
              <ion-row>
                  <ion-col col-12>{{ resultado.metrics.claims.rate}}</ion-col>
              </ion-row>
              <ion-row>
                  <ion-col col-12>%</ion-col>
              </ion-row>
          </ion-col>
        </ion-row>
      </ion-grid>
</ion-content>

image

Thanks