【发布时间】:2019-02-10 20:17:03
【问题描述】:
我有这个问题
无法读取未定义的属性“first_name”
这是我的 HTML 文件 checkout.html
<ion-content>
<ion-item>
<ion-label>First Name</ion-label>
<ion-input type="text" [(ngModel)]="newOrder.billing.first_name"></ion-input>
</ion-item>
....
</ion-content>
这是我的 ts 文件 checkout.ts
this.storage.get("userLoginInfo").then((userLoginInfo) => {
this.userInfo = userLoginInfo.user;
let email = userLoginInfo.user.email;
let id = userLoginInfo.user.id;
this.WooCommerce.getAsync("customers/email/"+email).then((data) => {
this.newOrder = JSON.parse(data.body).customer;
})
})
【问题讨论】:
-
显然
billing属性是undefined就像错误提示的那样。这是异步的,因此模板在数据到达之前呈现。当然它可能是undefined,原因是该道具不存在,但我猜问题是第一个。 -
newOrder 里面有什么?
-
我已经在构造函数 this.newOrder = {} 中声明了它; this.newOrder.billing = {}; this.newOrder.shipping = {}; this.billing_shipping_same = false;
-
好的,那么您获得的数据可能不存在
billing属性。就像 NullPointer 评论的那样,分配数据后newOrder的内容是什么?
标签: javascript angular typescript ionic3 woocommerce-rest-api