So I keep getting this error "TypeError: Cannot read property 'otherDocumentaryEvidence' of undefined". I understand I need to initialise this object somehow but I am unsure of the process of this. My understanding is that the object gets defined during the ngOnInit stage from a template service
ngOnInit(): void {
this._templateService
.getTemplateSnapshot(this.template)
.responseData()
.subscribe(templateSnapStream => {
return this.shareCase = templateSnapStream.result;
})
}
My object looks like this
export class ShareCase {
shareCaseReason?: string;
caseDetails?: ICasedeit;
involvedPersonsAndOrganisations?: IInvolved;
policeOfficer?: IPolice;
incidents?: IIncident;
offences?: IOffence;
suspect?: ISuspectDetails
witnessStatements?: IStatements;
interviewNotes?: IIncident;
notebookEntries?: INotebook;
victims?: IVictim;
witnesses?: IWitness;
physicalEvidence?: IEvidence;
otherDocumentaryEvidence?: IDocEvidence;
}
In my component code I initialise both the Share Case object and the otherDocumentaryEvidence object in the constructor like so:
this.shareCase = new ShareCase();
this.shareCase.otherDocumentaryEvidence = new IDocEvidence();
But I still get the same error? I am unsure of why this is. The line in my template which calls this object also looks like this
<div *ngIf='shareCase && shareCase.case.otherDocumentaryEvidence && shareCase.case.otherDocumentaryEvidence.length > 0'>
Any help would be greatly appreciated!