【问题标题】:how to fix 'Property 'dials' does not exist on type 'Object' in typeScript如何修复 typeScript 中的“对象”类型上不存在“属性”拨号
【发布时间】:2020-02-24 11:45:31
【问题描述】:
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=[];

【问题讨论】:

    标签: javascript json typescript arraylist angular7


    【解决方案1】:

    问题在于revenueTargetProgress 属性的类型。

    ObjectObject javascript 原型的类型。除了前面有extends 之外,它本身并没有多大意义。您可以在this threadthis thread 中详细了解anyObjectobject{} 之间的区别。

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

    【讨论】:

    • 实际上 'revenueTargetProgress' 是 Json 我从 'fusionCharts' 得到它我无法对其进行更改
    • 您不必对其进行更改。你必须给它分配一个类型
    猜你喜欢
    • 2019-06-08
    • 2021-12-30
    • 2018-08-25
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2023-04-02
    • 2018-08-17
    • 1970-01-01
    相关资源
    最近更新 更多