【发布时间】:2019-10-07 21:39:24
【问题描述】:
我有一个 SVG 元素,我想在 Angular 中的某个位置添加一个 matTooltip。我观察到,如果我尝试像这样添加 matTooltip:
generate() {
var svgEle = document.getElementById("testSVG");
var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttribute('id', "rect");
rect.setAttribute('x', "73");
rect.setAttribute('y', "95");
rect.setAttribute('class', "st01");
rect.setAttribute('width', "407");
rect.setAttribute('height', "328");
rect.setAttribute('matTooltip', "Info about the action");
svgEle.append(rect)
}
使用html测试代码:
<div style="width:400px">
<svg version="1.1" id="testSVG" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1000 1000" style="enable-background:new 0 0 1000 1000;"
xml:space="preserve">
<style type="text/css">
.st01{fill:#F99191;}
.st11{fill:#92B1F7;}
</style>
<rect x="638.5" y="146" class="st11" width="236" height="219"
matTooltip="Info about the action"/>
</svg>
</div>
<button mat-stroked-button (click)="generate()">Generate</button>
它不起作用。
这种情况到底是什么问题?
【问题讨论】:
-
您能否提供有关 stackblitz 的完整示例?
-
我不确定如何将它与 Angular 材料一起使用
-
使用可以使用这个模板:stackblitz.com/edit/angular-mat-tooltip
-
title属性是否适用于此?你真的需要matTooltip吗? -
标题有点慢,想加点样式
标签: angular svg angular-material tooltip