javascript - 使用指令以编程方式实例化 SVG 元素
问题描述
我会在基于 SVG 文件的角度项目中使用工具提示模块。
我必须动态生成工具提示。
我应该使用 JS 来添加matTooltip
属性
这是我所做的:
ngAfterViewInit() {
const cir1 = document.createElementNS("http://www.w3.org/2000/svg", "circle");
cir1.setAttribute("cx", "80");
cir1.setAttribute("cy", "50");
cir1.setAttribute("r", "30");
cir1.setAttribute("fill", "green");
let svg = document.getElementById('svg');
cir1.setAttribute('matTooltip', 'N8688');
svg.appendChild(cir1)
}
悬停时没有显示任何工具提示。
但是当我将matTooltip
属性直接应用于 SVG 时,它就可以工作了。
更新
我应该动态添加指令,但我找不到办法。
解决方案
推荐阅读
- open-policy-agent - 使用 rego 比较输入列表中的前后值
- apache-kafka - Kafka - 如果分区丢失如何恢复?
- python - 我可以在 np.mean() 中使用 str 吗?
- c# - 罗技 G-KEY MACRO SDK(C#):按下鼠标按钮时无法进入配置文件
- linux - Linux:动态加载器选择了错误的库?
- html - 我的类 flex wrap 不适用于 div 项
- javascript - 在 ejs 文件中调用用户定义的 JavaScript 函数
- ruby - 如何使用 Axlsx gem 自动使作为链接的文本成为超链接?
- c# - API:调用 HttpGet 后解析期间 Http 失败
- python - 将 LP 从 Excel 转换为 Python Pulp