林世哲 2019-08-30 14:34 采纳率: 0%
浏览 392

typescript里怎么用h5新标签?

最近要写一个拍照功能,angular+ts,在用h5标签的时候(video, canvas)出现了问题

canvas为例:
如果我这么写

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

就会报错:

 Property 'getContext' does not exist on type 'HTMLElement'.

如果我这么写

@ViewChild('canvas') private canvas: HTMLCanvasElement;

运行的时候报

ERROR TypeError: this.canvas.getContext is not a function

我服了,video标签也是这样
应该怎么办啊,求助各位大佬!!!!!!

  • 写回答

1条回答 默认 最新

  • 林世哲 2019-08-30 14:58
    关注

    解决了
    这么写:
    @ViewChild('canvas') private canvas: ElementRef;
    用的时候:
    this.canvas.nativeElement.getContext('2d');
    忘记写nativeElement了,佛了,难住了我两天,快哭了md

    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常