📌  相关文章
📜  类型“HTMLElement”上不存在属性“on”. - HTML代码示例

📅  最后修改于: 2022-03-11 14:52:52.555000             🧑  作者: Mango

代码示例2
To prevent this error you can write:

var plotDiv: any = document.getElementById('myDiv');
plotDiv.on('plotly_relayout', ...
document.getElementById('myDiv') return HTMLElement. This type doesn't contain method
on because this method is added within plotly-latest.min.js. So in order to silence
the typescript warning you can explicity say compile not to check types for plotDiv

Another way is create type definition like:

interface PlotHTMLElement extends HTMLElement  {
  on(eventName: string, handler: Function): void;
}

var plotDiv  = document.getElementById('myDiv')
plotDiv.on('plotly_relayout', function() {

});