【问题标题】:Angular2 custom tooltip on icon clickAngular2自定义工具提示图标点击
【发布时间】:2019-03-07 10:28:30
【问题描述】:

我想在单击图标时显示工具提示,而不是通过将鼠标悬停在其上。

<a title="Tooltip">
    <i class="fa fa-info-circle"></i>
</a>

我还希望能够使用以下类自定义工具提示:

<div class="a-tooltip a-tooltip--top-right">
  This is my tooltip text!
</div>

我的尝试:

<a (click)="tooltip.toggle()"
   #tooltip="matTooltip"
   matTooltip="test"
   aria-label="Button that displays a tooltip when focused or hovered over">
   <i class="fa fa-info-circle"></i>
</a>

但是,这不会在单击时显示工具提示。 在 app.module.ts 我有:

import { MatTooltipModule } from '@angular/material';

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        MatTooltipModule 
    ]
})

【问题讨论】:

  • 到目前为止你尝试了什么?你哪里失败了?
  • @emkay 查看更新。

标签: html angular tooltip


【解决方案1】:

默认情况下,mat-tooltip 是为鼠标悬停而设计的。如果您想禁用它,请使用以下代码:

<span matTooltip="Tooltip!" 
  (mouseenter)="$event.stopImmediatePropagation()" 
  (mouseleave)="$event.stopImmediatePropagation()"
  #tooltip="matTooltip" (click)="tooltip.toggle()">Test</span> 

【讨论】:

  • 有了这个,我可以让一个图标可点击。但是,工具提示不会显示在单击的元素附近,而是在我的页面底部,页脚下方放置了一个 mat-tooltip-component...
  • 请举个例子。
猜你喜欢
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多