Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

How to Solve Property ‘getContext’ does not exist on type ‘HTMLElement’ error in Angular 12 & TypeScript

...
let canvas: HTMLCanvasElement = document.getElementById("myChart") as HTMLCanvasElement;
// We can also do like this // let canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById("myChart");
// This one is accepted but not recommended // let canvas: any = document.getElementById("myChart");
this.ctx = canvas.getContext('2d');
...
Source by howtojs.io #
 
PREVIOUS NEXT
Tagged: #How #Solve #Property #exist #type #error #Angular #TypeScript
ADD COMMENT
Topic
Name
8+6 =