Inaccessible attribute value

Asked

Viewed 81 times

-5

Hello, I’m trying to get the attribute of an object in my view but I can’t, whenever I try to give Undefined

"Controller" Controller

Service Serviço

Interface Interface

View (backend) view back

View Front (brownser) View Front (brownser)

So far in this way I can visualize my entire object in my view, but if I try to access any attribute, it gives error as the images below:

View (backend) View Backc acessando atributo do objeto

On line 11 I am trying to access an attribute of my object criteria, but the following error appears:

undefined

Any lights at the end of the tunnel? I am already grateful

  • 1

    Please edit your question and add the code inves de prints.

  • https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5485#5485

2 answers

0

Your problem is due to you being working with asynchronous data. When your application starts, its variable criterias is undefined, and will only receive value when the observable returned by .getCustomerCritira() be complete.

So your view will try to access an attribute that doesn’t exist yet.

If you are with the newer versions of Ionic, an alternative would be to transform your variable criterias in a data stream.

Your . ts would look something like this:

export class FormAuditoria {

  /* seu codigo */

  criteriasObservable: Observable<AuditCustomerCriterionInterface>;

  constructor() {
    this.criteriasObservable = this.auditCustomerCriterionProvider
      .getCustomerCriteria(this.cucr_crit_id, this.audi_id);
  }
}

Your view:

<ion-card *ngIf="criteriasObservable | async as criterias">
    <ion-card-content>
        {{ criterias.aucc_id }}
    </ion-card-content>
</ion-card>

:)

-1


You are trying to access a property that has not been initialized and will only be set after an http request. To get around this the easiest way and use ngIF

<ion-card *ngIf="criteria">

{{citieria.aucc_id}}
  • Please consider adding a minimal explanation to your reply.

  • 1

    I was waiting for him to post the code as text...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.