【发布时间】:2020-08-04 09:19:57
【问题描述】:
大家好,最近我开始学习一些 Angular。
目前我收到以下错误:
32 this.warning.error.push(entry.name+': '+entry.error);
~~~~~
src/app/dashboard/dashboard.component.ts:33:15 - error TS2339: Property 'id' does not exist on type 'Warning[]'.
33 this.warning.id.push(entry.id);
~~
src/app/dashboard/dashboard.component.ts:37:13 - error TS2339: Property 'error' does not exist on type 'Error[]'.
37 this.error.error.push(entry.name+': '+entry.error);
~~~~~
src/app/dashboard/dashboard.component.ts:38:13 - error TS2339: Property 'id' does not exist on type 'Error[]'.
38 this.error.id.push(entry.id);
~~
问题是我为这两个 importet 定义了接口。
export interface Error {
id: number;
error: string;
}
export interface Warning {
id: number;
error: string;
}
正如你在我的组件中看到的那样。
import { Error, Warning } from '../dashboard';
...
export class DashboardComponent implements OnInit {
error: Error[];
warning: Warning[];
...
evaluate(): void{
for (let entry of this.status){
if (entry.status === 0){
this.ok = this.ok + 1;
}
if (entry.status === 1 && entry.value < 8){
this.warnings = this.warnings + 1;
this.warning.error.push(entry.name+': '+entry.error);
this.warning.id.push(entry.wt_id);
}
if (entry.status === 1 && entry.value >= 8){
this.critical = this.critical + 1;
this.error.error.push(entry.wt_name+': '+entry.error);
this.error.id.push(entry.wt_id);
}
}
}
我已经尝试了一些我在旧帖子中找到的东西,但似乎没有任何效果。
也许你们中的一些人知道解决方法并可以指出来。也许只是我错过了一些东西。
干杯!
【问题讨论】:
标签: angular typescript