首页 > 解决方案 > TS2339:“BatchDashboardComponent”类型上不存在属性“batch”

问题描述

所以我试图在这个 pug 文件的表上显示一些模拟数据

  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch='')
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}

但是我不断收到错误消息,说“BatchDashboardComponent”类型上不存在属性“batch”

这是我的打字稿文件

import { Component, OnInit } from '@angular/core';
import { BatchData } from '../../util/data';
import { BATCHES } from '../../util/mock-data';
import { BatchService } from '../../services/batch/batch.service';

@Component({
  selector: 'batch-dashboard',
  templateUrl: './batch-dashboard.component.pug',
  styleUrls: ['./batch-dashboard.component.scss'],
  providers: [BatchService]
})
export class BatchDashboardComponent implements OnInit {
  batches: BatchData[];

  constructor(){

  }

  ngOnInit(){
    this.batches = BATCHES;
    console.log(this.batches);
  }
}

其中 BATCHES 是 BatchData 类型的模拟数据,如下所示

export interface BatchData {
  batchId: number,
  batchStart: string,
  batchEnd: string,
  quantityMismatched: number,
  quantityEvaluated: number
}

关于我为什么会收到此错误的任何想法将不胜感激?

编辑:我也试过做这些无济于事

.centered-col-8
  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch)
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}
.centered-col-8
  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch [ngForOf]="batches")
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}

标签: angulartypescriptprimeng

解决方案


我想我解决了这个问题,我将它添加到打字稿文件中,错误消失了

batch: BatchData;

推荐阅读