Attribute value inaccessible

-5

Hello, I'm trying to get the attribute of an object in my view but I can not, whenever I try it gives undefined

"Controller"

Service

Interface

View(backend)

ViewFront(brownser)

  
    

SothiswayIcanseeallmyobjectinmyview,butifItrytoaccessanyattribute,itgivesanerroraccordingtotheimagesbelow:

  

View(backend)

Online11I'mtryingtoaccessanattributeofmycriteriaobject,butthefollowingerrorappears:

Any light at the end of the tunnel? I'm grateful already

    
asked by anonymous 22.08.2018 / 19:46

2 answers

-1

You are attempting 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}}
    
23.08.2018 / 10:21
0

Your problem occurs because you are working with asynchronous data. When your application starts, its% variable with% is undefined, and will only receive the value when the observable returned by criterias is complete.

So your view will try to access an attribute that does not yet exist.

If you have the newer versions of ionic, an alternative would be to transform your .getCustomerCritira() variable into 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>

:)

    
23.08.2018 / 17:14