Angular 中的签入组件为空

我有一个 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;


那么如何解决这个问题呢?谢谢你。所以会很好地解决这个问题


BIG阳
浏览 151回答 1
1回答

红颜莎娜

当您在 gotoItem 中将 ShowingSingle 设置为 true 时,将启用该元素。但是在您启用它的那一刻,您的单身还没有设置。请在您的开关箱之后将 ShowingSingle 设置为 true。gotoItem(index, type: string) {&nbsp; &nbsp; // NOT HERE&nbsp; &nbsp; switch (type) {&nbsp; &nbsp; &nbsp; case 'correspondence': {&nbsp; &nbsp; &nbsp; &nbsp; this.single = this.correspondenceEntries[index];&nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; case 'attachments': {&nbsp; &nbsp; &nbsp; &nbsp; this.single = this.attachmentEntries[index];&nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; default: {&nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; this.showingSingle = true; // BUT HERE&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript