组件上的@input输入错误:类型上不存在属性'showingSingle'

时间:2019-09-18 14:01:28

标签: javascript html angular input

所以我有一个8号角的应用程序。

我在组件DossierCorrespondenceComponent中拥有这个:

  @Input() showingSingle = false;

以便可以在其他组件(DossierCorrespondenceListComponent)中使用它。但是如果我这样做:

<div *ngIf="!showingSingle && correspondenceEntries && correspondenceEntries.length > 0;">

然后我会收到此错误:

Property 'showingSingle' does not exist on type 'DossierCorrespondenceListComponent'.

那该如何解决呢?

谢谢

html:

<div *ngIf="!showingSingle  && correspondenceEntries && correspondenceEntries.length > 0;">
  <div class="main-row main-row-dossier">
    <section class="data-entry">
      <h3 class="dossier-header">Algemeen</h3>
      <table class="dossier-table">
        <thead class="dossier-tableheader">
          <tr>
            <th class="dossier-tablehead fixed-one-fifth">Datum</th>
            <th class="dossier-tablehead fixed-four-fifths">Onderwerp</th>
          </tr>
        </thead>
        <tbody class="dossier-tablebody">
          <tr class="dossier-correspondencerow" *ngFor="let entry of correspondenceEntries; let i = index" (click)="gotoItem(i, entry.type)">
            <td>{{ entry.date | date:"dd-MM-y" }}</td>
            <td>{{ entry.name }}</td>
          </tr>
        </tbody>
      </table>
    </section>
  </div>
</div>

js:

export class DossierCorrespondenceListComponent implements OnInit {

  correspondenceEntries: DossierEntry[];

  constructor() { }

  ngOnInit() {
  }

js:

export class DossierCorrespondenceComponent implements OnInit {

  @Input()
  allCorrespondence: Array<DossierEntry>;
  @Input()
  correspondenceEntries: Array<DossierEntry>;
  @Input()
  attachmentEntries: Array<DossierEntry>;
 /*  allCorrespondence$: Observable<DossierEntry>;
  correspondenceEntries$: Observable<DossierEntry>;
  attachmentEntries$: Observable<DossierEntry>; */
  message = '';
  emptyMessageCorrespondentie = 'Geen correspondentie.';
  errorMessageConnection = 'Er ging iets mis met de connectie. Probeer over enkele minuten nogmaals.';

  correspondenceLoaded = false;

  @Input() showingSingle = false;

  single: DossierEntry;

  constructor(
    private healthAPIService: HealthAPIService,
    private prevRouterService: PreviousRouteService,
    private dossierService: DossierService
  ) {}

  ngOnInit() {
    this.healthAPIService.getDossierEntry('correspondence').subscribe(result => {
      this.handleCorrespondenceLoad(result), (this.correspondenceLoaded = true);
    }, msg => (this.message = this.errorMessageConnection));
  }

  handleCorrespondenceLoad(result) {
    if (result.length === 0) {
      this.message = this.emptyMessageCorrespondentie;
      return;
    }
    this.allCorrespondence = result;
    this.attachmentEntries = [];
    this.correspondenceEntries = [];

    const groups = _.groupBy(result, 'type');
    groups.correspondence.push(result);
    groups.attachments.push(result);

  }

  gotoItem(index, type: string) {
    this.showingSingle = true;

    /*    _.mapValues(type, function(group, key) {
      return type === 'correspondence' ? _.groupBy(group, 'attachments') : group;
}); */

    const groupData = _.groupBy(type, item => {
      return _.get(item, 'correspondence', 'attachments');
    });

    switch (type) {
      case 'correspondence': {
        this.single = this.correspondenceEntries[index];
        break;
      }
      case 'attachments': {
        this.single = this.attachmentEntries[index];
        break;
      }
      default: {
        break;
      }
    }
    this.showingSingle = true;
  }

  goBack(event) {
    this.showingSingle = false;
  }
}

你的意思是在这里

<tbody class="dossier-tablebody">
          <tr class="dossier-correspondencerow" *ngFor="let entry of correspondenceEntries; let i = index" (click)="gotoItem(i, entry.type)">
            <td>{{ entry.date | date:"dd-MM-y" }}</td>
            <td>{{ entry.name }}</td>
          </tr>
        </tbody>

这是DossierCorospondenceComponent的html:

<app-vital10-page [noTopBar]="true">
  <h2 class="dossier-page-header">Correspondentie</h2>

  <p class="data-entry" *ngIf="!allCorrespondence">{{ message }}</p>

  <app-is-loading *ngIf="!correspondenceLoaded" message="Correspondentie wordt geladen"></app-is-loading>


  <app-dossier-correspondence-list ></app-dossier-correspondence-list>

  <app-dossier-correspondence-item
    [item]="single"
    (goBack)="goBack($event)"
    *ngIf="showingSingle">
  </app-dossier-correspondence-item>
</app-vital10-page>


所以我这样子:

export class DossierCorrespondenceListComponent implements OnInit {

  correspondenceEntries: DossierEntry[];

  @Input() showingSingle = false;  

  constructor() { }

  ngOnInit() {
  }

但是我必须在这里输入

export class DossierCorrespondenceComponent implements OnInit {

  @Input()
  allCorrespondence: Array<DossierEntry>;
  @Input()
  correspondenceEntries: Array<DossierEntry>;
  @Input()
  attachmentEntries: Array<DossierEntry>;
 /*  allCorrespondence$: Observable<DossierEntry>;
  correspondenceEntries$: Observable<DossierEntry>;
  attachmentEntries$: Observable<DossierEntry>; */
  message = '';
  emptyMessageCorrespondentie = 'Geen correspondentie.';
  errorMessageConnection = 'Er ging iets mis met de connectie. Probeer over enkele minuten nogmaals.';

  correspondenceLoaded = false;

  @Input() showingSingle = false;

  single: DossierEntry;

  constructor(
    private healthAPIService: HealthAPIService,
    private prevRouterService: PreviousRouteService,
    private dossierService: DossierService
  ) {}

因为现在这是一个愚蠢的特性

1 个答案:

答案 0 :(得分:3)

您可以清楚地看到showingSingle中不存在DossierCorrespondenceListComponent,需要在DossierCorrespondenceListComponent内声明它才能使用它。

如果可以,请向我们显示您的DossierCorrespondenceListComponentDossierCorrespondenceComponent代码,以查看您想要实现的目标更好。

您可能会看到Angular Input的文档以获取更多信息Angular Input

更新1

简而言之:DCLC => DossierCorrespondenceListComponent和DCC代表DossierCorrespondenceComponent

我看到您要显示DCC组件列表,属性showingSingle需要绕过DCLC的值。

在您的ngFor循环中,像这样将showingSingle添加到循环中

<div *ngFor="let c of list">
  <DCC [showingSingle]="c"></DCC>
</div>

附注:组件名称应使用英语而不是法语,并且您正在与德国人一起工作