我这里有个突如其来的飞车-https://stackblitz.com/edit/ng-tootltip-ocdngb?file=src/app/bar-chart.ts
我有一个D3图表和一个角度应用程序。
当鼠标悬停在其上方时,它们会显示工具提示。
在较小的屏幕上,工具提示位于窗口的中心。
要做到这一点,我需要获得的工具提示的
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'.
这是错误,我可以停止它吗?
答案 0 :(得分:2)
您可以将tooltip.node()
强制转换为any
来解决此问题:
const toolTipWidth = (tooltip.node() as any).getBoundingClientRect().width;
正确的类型应该是HTMLElement
,它也应该起作用:
const toolTipWidth = (tooltip.node() as HTMLElement).getBoundingClientRect().width;