我有一个 angular 8 应用程序。如果加载了某个组件,我会收到一个错误无法读取未定义的属性“长度”我在谷歌上搜索了很多并做了一些教程。但是我不知道如何处理这个错误。所以如果我加载这个组件: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; constructor(private healthAPIService: HealthAPIService) {} handleCorrespondenceLoad(result) { if (result && result.length === 0) { this.message = this.emptyMessage; return; } this.allCorrespondence = result; this.attachmentEntries = []; this.correspondenceEntries = []; for (let entry of result) { switch (entry.type) { case 'correspondence': { this.correspondenceEntries.push(entry); break; } case 'attachments': { this.attachmentEntries.push(entry); break; } default: { console.log('Dossier correspondence heeft een invalide entry soort teruggegeven'); break; } } } } gotoItem(index, type: string) { this.showingSingle = true; // this.single = this.allCorrespondence[index]; switch (type) { case 'correspondence': { this.single = this.correspondenceEntries[index]; break; } case 'attachments': { this.single = this.attachmentEntries[index]; break; }
1 回答
暮色呼如
TA贡献1853条经验 获得超9个赞
尝试更改模板片段
<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>
<div *ngIf="!showingSingle && correspondenceEntries.length > 0">
到
<app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>
<div *ngIf="!showingSingle && correspondenceEntries && correspondenceEntries.length > 0">
似乎您正在尝试访问correspondenceEntries.length时它仍然没有定义
添加回答
举报
0/150
提交
取消