我正在尝试从作为另一个父对象的子对象的对象数组传递对象,作为子组件的输入。
Data object
export class CallauditHeaderClass {
//more fields here..
CallAuditDetails: CallauditDetailClass[];
}
Component Class:
constructor(){
this.currentcallaudit = new CallauditHeaderClass();
}
ngOnInit() {
this.getCallAuditTypes();
this.currentcallaudit.CallAuditDetails = [];
for (let callaudittype of this.callaudittypes) {
let tmpcallauditdetail: CallauditDetailClass;
tmpcallauditdetail = new CallauditDetailClass();
tmpcallauditdetail.CallAuditTypeId = callaudittype.CallAuditTypeId;
tmpcallauditdetail.CallAuditTypeCode = callaudittype.CallAuditTypeCode;
console.log(tmpcallauditdetail);
this.currentcallaudit.CallAuditDetails.push(tmpcallauditdetail);
}
}
getCallAuditDetailForAuditType(CallAuditTypeCode: string)
{
return this.currentcallaudit.CallAuditDetails.find(calldetail =>
calldetail.CallAuditTypeCode==CallAuditTypeCode);
}
HTML:
<app-callaudit-detail
[callauditdetail]= "getCallAuditDetailForAuditType
(callaudittype.CallAuditTypeCode)">
</app-callaudit-detail>
我试图在UI上以JSON格式显示currentcallaudit对象,但该对象未初始化。请告知如何使其正常工作。