angular - 在初始化之前使用属性“octomber”有问题
问题描述
@Component({
selector: 'app-adminpanel',
templateUrl: './adminpanel.component.html',
styleUrls: ['./adminpanel.component.scss']
})
export class AdminpanelComponent implements OnInit {
msg='';
november;
constructor(private _service : RegistrationService) {
this.getStatOctDetails();
}
public barChartOptions: ChartOptions = {
responsive: true,
// We use these empty structures as placeholders for dynamic theming.
scales: { xAxes: [{}], yAxes: [{}],
plugins: {
datalabels: {
anchor: 'end',
align: 'end',
}
}
};
public barChartLabels: Label[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
public barChartType: ChartType = 'bar';
public barChartLegend = true;
public barChartPlugins = [pluginDataLabels];
public barChartData: ChartDataSets[] = [
{ data: [this.octomber, 7, 2, 9, 5, 3, 1], label: 'Series A' },
{ data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B' }
];
在上面几行出现初始化问题之前使用了属性“octomber”
ngOnInit(): void {
}
getStatOctDetails(){
this._service.adminStatMonthOct().subscribe(
data => {console.log(data)
// this._router.navigate(['/login'])
this.octomber = data;
},
error =>{
console.log("error occur")
this.msg=error.error;
;
}
)
}
```
我使用了 Spring Boot 框架和 Angular。我从弹簧靴中获取 10 月的值(变量)。但是我在 10 月添加了 null
(octomber=null;),
然后错误消失了,但没有为我的图表显示任何值。我的项目的 octomber 值应该是 2
解决方案
推荐阅读
- javascript - javascript点击不同图片时隐藏li的元素
- python - Python - Windows 和 Linux 上相同 dict 值的不同哈希值
- javascript - 使用装饰器将类方法附加到窗口对象
- primeng - PrimeNG p-table 延迟加载和多排序 - 进入循环 - 超出最大调用堆栈大小
- python - 使用字符串分隔符拆分字符串,并将数据与分隔符一起显示
- osascript - osascript 使用包含路径的变量更改壁纸失败
- google-drive-api - 在 Google Drive Api 上更新领域文件
- firebase - Firebase 动态链接未推送到 Flutter 页面
- java - 使用带有 PKI SIM 的外部签名的 iText 签名 PDF
- java - 如何使用java将泰语单词从CSV文件保存到数据库表中?