Always Show Tooltip ( Angular Material2)

自闭症网瘾萝莉.ら 提交于 2019-12-12 06:27:05

问题


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)


回答1:


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



来源:https://stackoverflow.com/questions/44959479/always-show-tooltip-angular-material2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!