本文介绍了Chart Js的onClick函数中的Acess组件变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下组件,但无法在Chart的onClick函数内打印 test
变量值。
I have the following component, but I can't print test
variable value inside onClick function of Chart.
export class EntradaSaidaComponent {
@ViewChild('graficoDeBarraTemplate')
private graficoDeBarraTemplate;
graficoDeBarra: Chart;
test:any = "Test";
ngOnInit(){
this.graficoDeBarra = new Chart(this.graficoDeBarraTemplate.nativeElement, {
type: 'bar',
data: {
labels: ["Entrada", "Saída"],
datasets: [
{
backgroundColor: ["#00b050", "#00b0f0"],
data: [this.dashboard.totalReceber, this.dashboard.totalPagar],
label: this.sharedProvider.formatMoeda(this.dashboard.totalReceber)
},
{
backgroundColor: ["#03A9F4"],
data: [],
label: this.sharedProvider.formatMoeda(this.dashboard.totalPagar)
},
]
},
options: {
responsive: true,
plugins: {
},
legend: {
display: true,
position: 'bottom'
},
onClick: function(){
console.log(this.test);
},
},
});
}
}
如何解决?
推荐答案
使用箭头功能
onClick: () => {
console.log(this.test);
},
这篇关于Chart Js的onClick函数中的Acess组件变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!