如何修复类型脚本中的"对象"类型上不存在"属性'拨号'


import { Component, OnInit } from '@angular/core';
import { DashboardService } from 'src/app/provider/dashboard.service';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
revenueTargetProgress: Object;
dials: object;   
Guage = this.TotalRevenue;
constructor(private api: DashboardService) { 
this.revenueTargetProgress = {
chart: {
caption: "Revenue Target Progress",
lowerLimit: "0",
upperLimit: "100000000",
showValue: "1",
numberPrefix: "₹ ",
theme: "fusion",
showToolTip: "0"
},
// Chart Data
colorRange: {
color: [
{
minValue: "0",
maxValue: "30000000",
code: "#F2726F"
},
{
minValue: "30000000",
maxValue: "80000000",
code: "#FFC533"
},
{
minValue: "80000000",
maxValue: "1000000000",
code: "#62B58F"
}
]
},
dials: {
dial: [
{
value: "4800000"
}
]
}
}; 

}
ngOnInit() {
debugger;
this.api.getAllRevenueTarget().subscribe(res => {
this.TopCustomers = res;      
this.customerBarChart.data = this.TopCustomers;
this.TotalRevenue = this.TopCustomers.map(x => x.value).reduce((a, value) => a + value, 0);
let dials: any;
var Value = this.revenueTargetProgress.dials.dial[0].value = this.TotalRevenue;
//Value.dial[0].value = this.TotalRevenue;      
});

}

}

类型"Object"上不存在属性"dials"。如果出现此错误,我是Angular 7 typescript的新手。我想清除这个错误,仅此而已。我尝试声明dials:any;表盘:阵列;拨号:任意[]=[];拨号:任意=[];

问题在于revenueTargetProgress属性的类型。

ObjectObjectjavascript原型的类型。除了前面有extends之外,它本身没有太多意义。您可以在本线程或本线程中了解anyObjectobject{}之间的更多差异。

如果您知道revenueTargetProgress的类型,则可以指定它来代替Object。如果你不知道,并且你喜欢某种程度的风险,你可以指定any

最新更新