Search code examples
htmlangularng-bootstrapangular13

How to use isOpen method in ngbtooltip for angular 13?


I want to check whether to tooltip is open or not in angular 13 with use of isOpen() method.

Example:

<li class="mt-menu-icon-wrapper" placement="right" [ngbTooltip]="tooltip" triggers="manual"(mouseenter)="showTooltip('settings')" (mouseleave)="hideTooltip('settings')" 
[closeDelay]="300" (isOpen)="isOpenFlag" ></li> 

<ng-template #tooltip>
Welcome to New Year Party
</ng-template>`

Solution

  • according to ngbtooltip doc https://ng-bootstrap.github.io/#/components/tooltip/api

    isOpen is a method and not an input/output

    if you want to set a boolean when tooltip is open or not you can play with the two output hidden and shown

    hidden : An event emitted when the tooltip closing animation has finished. Contains no payload.

    shown : An event emitted when the tooltip opening animation has finished. Contains no payload.

    in your code it can look like

    <li class="mt-menu-icon-wrapper" placement="right" [ngbTooltip]="tooltip" triggers="manual"(mouseenter)="showTooltip('settings')" (mouseleave)="hideTooltip('settings')" 
    [closeDelay]="300" (shown)="tooltipDisplay(true)" (hidden)="tooltipDisplay(false)"></li>
    

    in controller have a method

    tooltipDisplay(isOpen:boolean) {
       this.isOpenFlag = isOpen;
    }