6

I would like to click on the span element once, so that the tooltip appears and then again to hide.

Here is my html. What am I doing wrong?

<span mdTooltip="Tooltip!" (click)="tooltip.toggle()>Test</span>
Paul Pinter
  • 165
  • 2
  • 8

1 Answers1

9

Template reference variable should help you to accomplish that:

<span matTooltip="Tooltip!" #tooltip="matTooltip" (click)="tooltip.toggle()">Test</span>

See also

TheRennen
  • 549
  • 4
  • 16
yurzui
  • 205,937
  • 32
  • 433
  • 399
  • Thank very much! You solved my problem. I was always wondering what '#' sign meant. – Paul Pinter Oct 05 '17 at 14:20
  • 3
    Althogh the solution is working but it looks to me it does noting with the hover effect which also show and hide the tooltip when the mouse move. How can you only manage the tooltip by click event and kind of switch off the react for hover effect? – Gabor Dec 07 '20 at 21:26
  • For auto hiding the tooltip you can add this event along with click event. Hope this will help. Do : (mouseleave)="tooltip.hide(300)" – Rahul Dudhane Nov 18 '21 at 15:26