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>
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With