Cannot read property 'native-element' of undefined

后端 未结 8 826
借酒劲吻你
借酒劲吻你 2020-12-09 02:34

I am using ionic 2.

I need to get HTML element value.

Actually, I used viewchild.

Here is my html template code

8条回答
  •  心在旅途
    2020-12-09 02:57

    I got this issue to display bar chart in ionic angular 9 project. My issue was resolved after adding timeout function

    @ViewChild('barChart') barChart;
    
    ngOnInit() {
      setTimeout(() => {
         this.createBarChart();
       }, 1000);
    }
    
    
     createBarChart() {
    
         this.bars = new Chart(this.barChart.nativeElement, {
         type: 'bar',
         data: {
           labels: this.chartLabels,
           datasets: [{
          label: 'Monthly Costings',
          data: [2.5, 3.8],
          backgroundColor: ['rgb(38, 194, 100)', '#548279'],
          borderColor: ['rgb(38, 194, 100)', '#548279'],
          borderWidth: 1
        }]
      },
      options: {
        scales: {
          yAxes: [{
            ticks: {
              beginAtZero: true
            }
          }]
        }
      }
    });
    }
    

提交回复
热议问题