簡體   English   中英

如何修復 typeScript 中的“對象”類型上不存在“屬性”撥號

[英]how to fix 'Property 'dials' does not exist on type 'Object' in typeScript

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 typescript 的新手。 我想清除這個錯誤就是這樣。 我嘗試通過聲明撥號:任何; 表盤:數組; 撥號:任何[] = []; 撥號:任何= [];

問題是revenueTargetProgress屬性的類型。

ObjectObject javascript 原型的類型。 除了前面有extends之外,它本身沒有多大意義。 您可以在此線程此線程中了解有關any Objectobject{}之間差異的更多信息。

如果您知道revenueTargetProgress的類型,您可以分配它來代替Object 如果您不知道它並且您喜歡某種程度的風險,您可以分配any .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM