错误TypeError:无法读取Object.eval上未定义的属性“ xxx” [作为updateDirectives]

时间:2019-06-13 05:49:17

标签: angular typescript ionic-framework

遇到错误:

  

无法在Object.eval读取未定义'Full_Name'的属性

<ion-item>
     <ion-label position="floating">Full Name</ion-label>
     <ion-input id="name" name=Full_Name #Full_Name="ngModel" [(ngModel)]="UpdateAddress.Full_Name"></ion-input>
</ion-item>

enter image description here

代码:

UpdateAddress Prop

2 个答案:

答案 0 :(得分:0)

  

无法读取未定义“全名”的属性

您正在输入中阅读它:

<ion-input id="name" name=Full_Name #Full_Name="ngModel"   [(ngModel)]="UpdateAddress.Full_Name"></ion-input>

该错误表示UpdateAddressundefinedhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined

修复

初始化模型中的UpdateAddress

答案 1 :(得分:0)

我会使用Safe Navigation Operator (?)

UpdateAddress?.Full_Name

您的代码:

<ion-item>
     <ion-label position="floating">Full Name</ion-label>
     <ion-input id="name" name=Full_Name #Full_Name="ngModel" [(ngModel)]="UpdateAddress?.Full_Name"></ion-input>
</ion-item>