Angular 如何定义对象数组,对象数组|角度2
我不断得到一个未定义类型错误“error-TypeError:cannotreadproperty'length'of undefined”。在我的类中,我有一个array对象,它有另一个array对象。基本上我有一个类似这样的类:Angular 如何定义对象数组,对象数组|角度2,angular,typescript,Angular,Typescript,我不断得到一个未定义类型错误“error-TypeError:cannotreadproperty'length'of undefined”。在我的类中,我有一个array对象,它有另一个array对象。基本上我有一个类似这样的类: export class ICase { shareCaseReason?: string; caseDetails?: ICasedeit; involvedPersonsAndOrganisations?: IInvolved; policeOf
export class ICase {
shareCaseReason?: string;
caseDetails?: ICasedeit;
involvedPersonsAndOrganisations?: IInvolved;
policeOfficers?: IPolice[];
incidents?: IIncident[];
offences?: IOffence[];
suspect?: ISuspectDetails[];
witnessStatements?: IStatements[];
interviewNotes?: IIncident[];
notebookEntries?: INotebook;
victims?: IVictim[];
witnesses?: IWitness[];
physicalEvidence?: IEvidence[];
otherDocumentaryEvidence?: IDocEvidence[];
}
export class ISuspectDetails {
ageRange: string;
juvenile: IJuvenile;
timeincustody: ITimeInCustody;
particularNeeds: IParticularNeeds;
complaints: IComplaint[];
principalEvidenceTypes: IEvidenceTypes;
motivationTypes: IMotivationTypes;
bailRecords: IBailRecords;
constructor() {
this.complaints = [];
};
}
<div class="container-fluid scrollable-grid" *ngIf='template && template.shareCase && template.shareCase.case && template.shareCase.case.suspects'>
<div class="row gridData" *ngFor="let suspect of template.shareCase.case.suspects">
<div class="col-2"> {{suspect?.chargeDate}} </div>
<div class="col-1"> {{suspect?.complaint?.length}} </div>
</div>
</div>
我想显示ISuspectDetails对象数组中的属性。该类如下所示:
export class ICase {
shareCaseReason?: string;
caseDetails?: ICasedeit;
involvedPersonsAndOrganisations?: IInvolved;
policeOfficers?: IPolice[];
incidents?: IIncident[];
offences?: IOffence[];
suspect?: ISuspectDetails[];
witnessStatements?: IStatements[];
interviewNotes?: IIncident[];
notebookEntries?: INotebook;
victims?: IVictim[];
witnesses?: IWitness[];
physicalEvidence?: IEvidence[];
otherDocumentaryEvidence?: IDocEvidence[];
}
export class ISuspectDetails {
ageRange: string;
juvenile: IJuvenile;
timeincustody: ITimeInCustody;
particularNeeds: IParticularNeeds;
complaints: IComplaint[];
principalEvidenceTypes: IEvidenceTypes;
motivationTypes: IMotivationTypes;
bailRecords: IBailRecords;
constructor() {
this.complaints = [];
};
}
<div class="container-fluid scrollable-grid" *ngIf='template && template.shareCase && template.shareCase.case && template.shareCase.case.suspects'>
<div class="row gridData" *ngFor="let suspect of template.shareCase.case.suspects">
<div class="col-2"> {{suspect?.chargeDate}} </div>
<div class="col-1"> {{suspect?.complaint?.length}} </div>
</div>
</div>
我想在我的组件中显示ngFor上ISuspectDetails投诉数组的长度。我的模板如下所示:
export class ICase {
shareCaseReason?: string;
caseDetails?: ICasedeit;
involvedPersonsAndOrganisations?: IInvolved;
policeOfficers?: IPolice[];
incidents?: IIncident[];
offences?: IOffence[];
suspect?: ISuspectDetails[];
witnessStatements?: IStatements[];
interviewNotes?: IIncident[];
notebookEntries?: INotebook;
victims?: IVictim[];
witnesses?: IWitness[];
physicalEvidence?: IEvidence[];
otherDocumentaryEvidence?: IDocEvidence[];
}
export class ISuspectDetails {
ageRange: string;
juvenile: IJuvenile;
timeincustody: ITimeInCustody;
particularNeeds: IParticularNeeds;
complaints: IComplaint[];
principalEvidenceTypes: IEvidenceTypes;
motivationTypes: IMotivationTypes;
bailRecords: IBailRecords;
constructor() {
this.complaints = [];
};
}
<div class="container-fluid scrollable-grid" *ngIf='template && template.shareCase && template.shareCase.case && template.shareCase.case.suspects'>
<div class="row gridData" *ngFor="let suspect of template.shareCase.case.suspects">
<div class="col-2"> {{suspect?.chargeDate}} </div>
<div class="col-1"> {{suspect?.complaint?.length}} </div>
</div>
</div>
非常感谢您的帮助!刚从Angular开始,我掌握了很多东西,但我似乎在任何地方都找不到解决这个问题的方法 您的html中有输入错误,
投诉
而不是投诉
。改为:
{{可疑?投诉?长度}
您的html中有一个输入错误,
投诉
,而不是投诉
。改为:
{{可疑?投诉?长度}
非常感谢你!我现在觉得很傻,因为我看不见它!非常感谢你!我现在觉得很傻,因为我看不见它!