Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing context to tooltip of ngx bootstrap

I'm working with tooltip in ngx-bootstrap, and want to pass data to the ng-template being to the tooltip. The documentation provides [tooltipContext], but it didn't seem to be working. I have provided a code snippet.

HTML:

<ng-template #tooltipTmpl let-view="view">
    <div class="tooltip-section">
        <div class="section-title">
            {{ view.dateRangeText }}
        </div>
        <div class="section-text">
            {{ view.data }}
        </div>
    </div>
</ng-template>
<div
    *ngIf="view.isVisible"
    [tooltip]="tooltipTmpl"
    [tooltipContext]="{view: view}"
    containerClass="white-tool-tip"
    placement="top"
                    >
  <div class="sub-title">
    {{ view.title }}
  </div>
</div>

REF: https://valor-software.com/ngx-bootstrap/#/tooltip

like image 536
L. C. Avatar asked Sep 05 '25 03:09

L. C.


2 Answers

I have face the same problem , so far I have check the source code the tooltipContext mark as deprecated you can do a work a round thi like this

you can still access to the view property inside the ng-template

<button type="button" class="btn btn-success"
          *ngIf="view.isVisible"
    [tooltip]="tooltipTmpl">
  Show me tooltip with html {{ view.title }}
</button>

<ng-template #tooltipTmpl>
    <h4>
        {{ view.dateRangeText }}
    </h4>
    <div>
        <i>
      {{ view.data }}
   </i>
    </div>
</ng-template>

demo πŸ”₯πŸ”₯

Updated πŸš€πŸš€

incase you want to use my solation with array of views , you juest need to move ng-template to the body of the ngFor.

template

<ng-container *ngFor=" let view of views">
    <button type="button" class="btn btn-success"
          *ngIf="view.isVisible"
    [tooltip]="tooltipTmpl">
  Show me tooltip with html {{ view.title }}
</button>
    <ng-template #tooltipTmpl>
        <h4>
            {{ view.dateRangeText }}
        </h4>
        <div>
            <i>
      {{ view.data }}
   </i>
        </div>
    </ng-template>
    <br>
    <br>
</ng-container>

demo πŸš€πŸš€

like image 116
Muhammed Albarmavi Avatar answered Sep 07 '25 21:09

Muhammed Albarmavi


I have used bootstrap popover in my projects, so would recommend using popover.

Also, there was an issue created on GitHub but the user ended up using popover - https://github.com/valor-software/ngx-bootstrap/issues/4775

like image 38
rkparmar Avatar answered Sep 07 '25 22:09

rkparmar