Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open tooltip on start

How can I open a tooltip from ngboostrap when openeing the compnent.

I tried called the open method in the ngOnInit function but it didn't show it.

I tried the same method in a button click an that worked (based on the sample: https://ng-bootstrap.github.io/app/components/tooltip/demos/tplwithcontext/plnkr.html )

Code:

export class TooltipComponent implements OnInit {
    @ViewChild('tleft') public tooltip: NgbTooltip;

    ngOnInit() {
        this.tooltip.open();
    }
}

Template:

<p>
  <strong ngbTooltip="Tooltip on left" #tleft="ngbTooltip" triggers="manual">Tooltip is here</strong>?
</p>
<button type="button" class="btn btn-secondary" (click)="open()">
  Open
</button>
like image 383
Stefan Avatar asked Apr 24 '26 10:04

Stefan


1 Answers

You should be calling this.tooltip.open(); inside ngAfterViewInit hook, not ngOnInit. The DOM might not be ready in ngOnInit. So, the solution is:

ngAfterViewInit() {
    this.tooltip.open();
}
like image 129
Max Koretskyi Avatar answered Apr 28 '26 16:04

Max Koretskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!