Moshe
Moshe

Reputation: 2684

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)

Upvotes: 3

Views: 8386

Answers (1)

Nehal
Nehal

Reputation: 13297

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

Upvotes: 6

Related Questions