angular - 将一个变量传递给另一个变量
问题描述
我正在创建一个从变量生成的饼图public pieChartData:number[] = [300, this.Goal]
。我正在尝试for
使用对象数组上的循环在构造函数中获取正确的数据
data = [{
Id: 1,
YTDGoal: 125000
}]
但是当传入pieChartData
,时this.Goal
是未定义的。
我该如何解决这个问题?
解决方案
尝试这个。
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
data = [{
Id: 1,
YTDGoal: 125000
}]
Goal;
public pieChartLabels:string[] = ['Download Sales', 'YTD Goal'];
public pieChartData:number[] = [300, this.Goal];
public pieChartType:string = 'pie';
public pieChartCustomColors = [{
backgroundColor: ['blue', 'red']
}]
constructor() {
for (let i = 0; i < this.data.length; i++) {
this.Goal = this.data[i].YTDGoal
}
this. pieChartData = [300, this.Goal];
}
public chartClicked(e:any):void {
console.log(e);
}
public chartHovered(e:any):void {
console.log(e);
}
}
推荐阅读
- apache - 无法使用 SSL 登录 GeoServer 2.19
- amazon-web-services - AWS EC2 成本比较在一处?
- node.js - npm 错误!代码 ENOTEMPTY npm 错误!在 Nextjs 项目中安装任何 npm 依赖项时的系统调用重命名
- python - 如何根据匹配使用熊猫样式为 excel 单元格着色?
- debugging - 在 WebStorm 中调试安全帽可靠性测试
- youtube - youtube VTT 字幕中的空行
- javascript - 为什么我的随机数会出现 Uncaught TypeError?
- python - Django 错误:NoReverseMatch at / ;查看错误的 urlpattern?
- docker - Docker 卷:持久化数据
- flutter - 带回来后隐藏顶部状态栏