我有一个 Angular 8 应用程序。但是我收到这个错误:在一个组件上。它是一个组件中的一个组件。如果组件为空,则将显示错误,如果组件不为空,则不会显示错误:4200/dossier-dossier-module-ngfactory.js:186 ERROR TypeError: Cannot read property 'length' of null at DossierCorrespondenceItemComponent.push../src/app/dossier/dossier-correspondence-item/dossier-correspondence-item.component.ts.DossierCorrespondenceItemComponent.ngOnInit (:4200/dossier-dossier-module-ngfactory.js:100) at checkAndUpdateDirectiveInline (vendor.js:37850) at checkAndUpdateNodeInline (vendor.js:46063) at checkAndUpdateNode (vendor.js:46025) at debugCheckAndUpdateNode (vendor.js:46659) at debugCheckDirectivesFn (vendor.js:46619) at Object.updateDirectives (:4200/dossier-dossier-module-ngfactory.js:189) at Object.debugUpdateDirectives [as updateDirectives] (vendor.js:46611) at checkAndUpdateView (vendor.js:46007) at callViewAction (vendor.js:46248)在这个组件上: <app-dossier-correspondence-item [item]="single" (goBack)="goBack($event)" *ngIf="showingSingle"> </app-dossier-correspondence-item></app-vital10-page>这是 ts 代码:import { Component, OnInit } from '@angular/core';import { HealthAPIService } from '../../shared/health-api/health-api.service';import { DossierEntry } from '../../interfaces/dossier/dossier-entry.interface';@Component({ selector: 'app-dossier-correspondence', templateUrl: './dossier-correspondence.component.html',})export class DossierCorrespondenceComponent implements OnInit { allCorrespondence: Array<DossierEntry>; correspondenceEntries: Array<DossierEntry>; attachmentEntries: Array<DossierEntry>; message = ''; emptyMessage = 'Geen correspondentie.'; errorMessage = 'Er ging iets mis met de connectie. Probeer over enkele minuten nogmaals.'; correspondenceLoaded = false; showingSingle = false; single: DossierEntry;那么如何解决这个问题呢?谢谢你。所以会很好地解决这个问题
1 回答
红颜莎娜
TA贡献1842条经验 获得超12个赞
当您在 gotoItem 中将 ShowingSingle 设置为 true 时,将启用该元素。但是在您启用它的那一刻,您的单身还没有设置。请在您的开关箱之后将 ShowingSingle 设置为 true。
gotoItem(index, type: string) {
// NOT HERE
switch (type) {
case 'correspondence': {
this.single = this.correspondenceEntries[index];
break;
}
case 'attachments': {
this.single = this.attachmentEntries[index];
break;
}
default: {
break;
}
}
this.showingSingle = true; // BUT HERE
}
添加回答
举报
0/150
提交
取消