0

我对 NgbTooltip 有一个要求,

  • 工具提示应允许包含带有“_blank”目标的超链接。例如:了解更多
  • 单击文档正文时,工具提示应隐藏。

以下是我的方法,并没有按预期工作。

<a [ngbTooltip]="hintTooltip" tabindex="0"  triggers="click:blur">hint</a>
<ng-template #hintTooltip>
  Sample hint description
  <a href="www.abc.com" target="_blank">Learn more</a>
</ng-template>

上面的代码通过显示超链接打开工具提示。但是当我单击超链接时,它没有打开一个新窗口,而是隐藏了工具提示。

堆栈闪电战: https ://stackblitz.com/edit/angular-viipeo-dqjmfh ?file=app/tooltip-triggers.html

感谢是否有人可以提供帮助

4

2 回答 2

1

已修复,如果有人感兴趣,以下是解决方案

.html

<a [ngbTooltip]="hintTooltip" tabindex="0"  triggers="click:blur">hint</a>
    <ng-template #hintTooltip>
      Sample hint description
      <a href="www.abc.com" target="_blank" (click)="nToolTip(t1, 'http://www.google.com');">Learn more</a>
    </ng-template>

.ts

_toolTipCollection = [];
nToolTip(tooltip, _url?: string): void {
    if (tooltip.isOpen()) {
        if (_url) {
            window.open(_url, '_blank');
        }
    }
    for (const tooltip of this._toolTipCollection) {
        tooltip.close();
    }
    this._toolTipCollection = [];

    tooltip.toggle();
    this._toolTipCollection.push(tooltip);
}
于 2019-01-02T02:04:25.807 回答
0

使用 ViewChild 获取对 Element 的引用,然后使用 tooltip 方法关闭

 @ViewChild('ref') ref;
  @HostListener('mouseleave',['$event']) onHoverOutside(){
   this.ref.close();
  }

示例:https:https: //stackblitz.com/edit/angular-viipeo

于 2018-08-09T03:40:16.093 回答