Angular 角度D3-属性';getBoundingClientRect';不存在于类型';窗口';
我这里有一场闪电战- 我有一个D3图表和角度应用程序 当鼠标悬停在这些条上时,它们会显示工具提示 在较小的屏幕上,工具提示位于窗口的中心 要做到这一点,我需要的工具提示,我得到的Angular 角度D3-属性';getBoundingClientRect';不存在于类型';窗口';,angular,typescript,d3.js,Angular,Typescript,D3.js,我这里有一场闪电战- 我有一个D3图表和角度应用程序 当鼠标悬停在这些条上时,它们会显示工具提示 在较小的屏幕上,工具提示位于窗口的中心 要做到这一点,我需要的工具提示,我得到的 const toolTipWidth = tooltip.node().getBoundingClientRect().width; 这在这里很好用,但我的实际应用程序是Angular cli应用程序 应用程序仍在运行,但我收到了错误消息 error TS2339: Property 'getBoundingClie
const toolTipWidth = tooltip.node().getBoundingClientRect().width;
这在这里很好用,但我的实际应用程序是Angular cli应用程序
应用程序仍在运行,但我收到了错误消息
error TS2339: Property 'getBoundingClientRect' does not exist on type 'BaseType'.
Property 'getBoundingClientRect' does not exist on type 'Window'.
这是一个错误,我能阻止它吗 您只需将
tooltip.node()
转换为any
即可:
const toolTipWidth = (tooltip.node() as any).getBoundingClientRect().width;
正确的类型可能应该是HTMLElement
,这样也可以:
const toolTipWidth = (tooltip.node() as HTMLElement).getBoundingClientRect().width;