Javascript 在Angular 2应用程序中打印单击事件
我试图在angular 2项目中使用plotly java脚本单击事件,但它返回以下错误 类型“HtmleElement”上不存在属性“on”Javascript 在Angular 2应用程序中打印单击事件,javascript,angular,plotly,jquery-click-event,Javascript,Angular,Plotly,Jquery Click Event,我试图在angular 2项目中使用plotly java脚本单击事件,但它返回以下错误 类型“HtmleElement”上不存在属性“on” let myPlot = document.getElementById('donutChartId'); myPlot.on('plotly_click', function(data){ console.log(data.points[0].label); }); 因此,角度构建失败。.on()是一个 如果您在应用程序中使用Jquery,则可以从所
let myPlot = document.getElementById('donutChartId');
myPlot.on('plotly_click', function(data){
console.log(data.points[0].label);
});
因此,角度构建失败。.on()
是一个
如果您在应用程序中使用Jquery,则可以从所选元素创建Jquery对象以使用此方法
let myPlot = document.getElementById('donutChartId');
to
let myPlot = $(document.getElementById('donutChartId'));
希望这有帮助 我认为这更像是一个编译错误。但是你的代码可以工作。如果你担心这个错误。您可以为ES6 HtmleElement类创建子类。在组件中添加上面的代码
class CustomHTMLElement extends HTMLElement {
constructor() {
super();
}
on(event_type, cb) {
}
}
和类型铸入元素选择
让myPlot=document.getElementById('donutChartId')代码>我以前试过,但它说“找不到名称“$”,您为jquery添加了类型吗?您应该安装类型,类似的内容应该在您对类型“@types/jquery”:“1.10.31”的依赖项中,并且实际的jquery库应该是您的应用程序的一部分。