问题:property ‘getcontext’ does not exist on type
框架:angular
语言:typescript
解决方法:
Html代码
<canvas id="mycvs" width="300" height="300" ></canvas>
ts代码
var canvas = <HTMLCanvasElement> document.getElementById("mycvs");
var ctx = canvas.getContext("2d");
或者
var canvas : any = document.getElementById("mycvs");
var ctx = canvas.getContext("2d")
ngAfterViewInit() 初始化完组件视图及其子视图之后调用
ngAfterViewInit(){
var canvas:any=document.getElementById("mycvs");
var ctx=canvas.getContext("2d");
ctx.strokeStyle='red';
ctx.arc(0,10,100,0,0.5*Math.PI);
ctx.stroke();
}