[英]Using MatToolTip with icons in Angular 5
I am able to use MatToolTip
along with a button element:我可以将MatToolTip
与按钮元素一起使用:
<button mat-mini-fab color="primary" (click)="fn()">
<span matTooltip="myMessage">
<i class="material-icons">delete</i>
</span>
</button>
But on trying to use it with an icon which is within a div
or span
tag, it doesn't work:但是在尝试将它与div
或span
标签内的图标一起使用时,它不起作用:
<div matToolTip="myMessage">
<i style="line-height: 0px; font-size: 25px; cursor: pointer; " (click)="fn()" class="material-icons">delete</i>
</div>
What am I doing wrong?我究竟做错了什么?
Just use the official material icon element:直接使用官方的材质图标元素:
<mat-icon matTooltip="My tooltip">delete</mat-icon>
You can of course style it however you want, enclose it in a div and give that div a class, add event listeners, etc.您当然可以随意设置样式,将其包含在 div 中并为该 div 提供一个类,添加事件侦听器等。
For anyone stuck with tooltips not working, please double-check your app.module.ts file.对于任何因工具提示不起作用而卡住的人,请仔细检查您的 app.module.ts 文件。 Make sure that your imports: [...]
array includes MatTooltipModule
, and that you are importing MatTooltipModule with the other imports.确保您的imports: [...]
数组包含MatTooltipModule
,并且您正在将 MatTooltipModule 与其他导入一起导入。
If you don't include these things, tooltips simply won't work, yet there will also be no errors in the console.如果您不包含这些内容,工具提示将无法正常工作,但控制台中也不会出现错误。
I got stuck wondering why my <mat-icon matTooltip="test">warning</mat-icon>
wasn't working, turns out this is why.我一直想知道为什么我的<mat-icon matTooltip="test">warning</mat-icon>
不起作用,事实证明这就是原因。
对于希望将变量绑定到matTooltip
任何人,您需要使用表达式[matTooltip]
将其绑定,因此它看起来像这样:
<mat-icon class='colorInfo' [matTooltip]="tooltipVariable">info_outline</mat-icon>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.