如何在typeScript的'Object'类型上不存在'属性'dials'的修复方法

问题描述 投票:0回答:1
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;      
    });



  }



}

属性“拨号”在“对象”类型上不存在,出现此错误,我是Angular 7打字稿的新手。我想清除这个错误就是这样。我试图通过宣布拨号:任何;表盘:数组;拨打:any [] = [];拨打:any = [];

javascript json typescript arraylist angular7
1个回答
0
投票

问题是revenueTargetProgress属性的类型。

ObjectObject JavaScript原型的类型。除了extends之外,它本身没有太多意义。您可以在anyObject中详细了解object{}this threadthis thread之间的区别。

如果知道revenueTargetProgress的类型,则可以代替Object进行分配。如果您不知道并且喜欢某种程度的风险,则可以分配any

© www.soinside.com 2019 - 2024. All rights reserved.