Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always Show Tooltip ( Angular Material2)

I have somebuttons

            <button mdTooltip="bye" mdTooltipPosition="left" md-mini-fab>
                BYE
            </button>
            <button mdTooltip="hi" mdTooltipPosition="left" md-mini-fab>
                HI
            </button>

The tooltips show on "hover" by default. Is there a way to make it always show? (Show on page load and stay)

like image 708
Moshe Avatar asked Mar 06 '26 13:03

Moshe


1 Answers

First add imports:

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

then add reference names to tooltips:

<div>
  <button #tooltipBye="mdTooltip" 
          mdTooltip="bye" 
          mdTooltipPosition="below" 
          md-mini-fab>
          BYE
  </button>
  <button #tooltipHi="mdTooltip"
          mdTooltip="hi" 
          mdTooltipPosition="below" 
          mdTooltipHideDelay="1000" 
          md-mini-fab>
          HI
    </button>
</div>

Pass references of these elements in the component. Then use AfterViewChecked lifecycle hook to call the show() method.

component.ts:

@ViewChild('tooltipHi') tooltipHi: MdTooltip;
@ViewChild('tooltipBye') tooltipBye: MdTooltip;

ngAfterViewChecked(){

  if(this.tooltipHi._isTooltipVisible() == false){
    this.tooltipHi.show();
  }
  if(this.tooltipBye._isTooltipVisible() == false){
    this.tooltipBye.show();
  }

}

Here's the demo

like image 135
Nehal Avatar answered Mar 09 '26 02:03

Nehal