angular - 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}}
解决方案
我想我解决了这个问题,我将它添加到打字稿文件中,错误消失了
batch: BatchData;
推荐阅读
- docker - 将文件从 docker 容器保存到主机
- docker - docker-compose 中的 ffmpeg 无法启动
- bash - 数组中带有空格的字符串元素被拆分?
- r - 从 ggplot2 中的图例类别中删除 stat_summary 符号
- java - JNI CPP gradle 未找到 jni.h
- angular - 使用 angular、blob 和 createObjectURL 读取视频
- scala - 带有逗号分隔的其他列的 Spark DataFrame 列,这些列需要使用另一列中给出的值进行更新
- javascript - Puppeteer 和 react-router (BrowserRouter)
- python - GCP Python 在存储桶之间复制大文件
- android-studio - 在 AS 3.6.1 中移动资源管理器选项卡