【发布时间】:2017-04-21 21:06:18
【问题描述】:
我将数据传递到一个可访问的子组件中,我可以使用这些数据构建我的视图。但是,我需要访问 @Input 对象上的属性以“查找”数组中具有相同值的项。相当简单直接。当组件加载时,我在构造函数中执行此操作,以便立即可用。
但是,@Input 对象返回未定义,因此我无法访问该属性。有人可以看看并告诉我这里发生了什么吗?
返回未定义的对象是“this.ConfirmOrderData”,就像我说的,我可以对这个对象的属性数组等执行 ngFor 重复,所以我很困惑为什么它是未定义的。
代码:
@Input() ConfirmOrderData:{
orderRefillData: Array<any>,
selectedUser: any,
DeliveryTypeId: any,
PickupLocationId: any,
PaymentTypeId: any,
AddressType: any
};
constructor(
fb: FormBuilder,
public refillService: refillService,
public globalService: globalService
) {
this.userInfo = this.globalService.getUserInfo();
this.deliveryAddress = this.userInfo.userInfo.StreetAddresses.find((item) => item.DeliveryTypeId == this.ConfirmOrderData.AddressType.AddressTypeId)
//the this.ConfirmOrderData object in the above line comes back undefined. Don't know why.
}
【问题讨论】:
-
当您直接在模板中使用属性时,例如未观察到的数据必须定义或者您可以使用?喜欢
data?.item?.couldbelate
标签: angular typescript