[Chartjs]-ERROR TypeError: "this.canvas is undefined" | Problem with creating a chart with angular and chart.js

3👍

The canvas element will not be rendered (written to the DOM) until chart is true

<div *ngIf="chart">
    <canvas #canvas></canvas>
</div>

Because chart is initially undefined, the canvas ViewChild does not exist, which explains why "this.canvas is undefined".

Try removing *ngIf="chart" to test your chart.

<canvas #canvas></canvas>

Leave a comment