Angular2 (2.0.0-rc.4) I use Bootstrap's Tooltip, Tooltip need execute follow javascript when ready:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
In Angular2,how to execute it?
That worked for me:
import { Directive, ElementRef, Input, HostListener, OnDestroy } from '@angular/core';
declare var $: any;
@Directive({
selector: '[appTooltip]'
})
export class TooltipDirective implements OnDestroy {
@Input()
public appTooltip: string;
constructor(private elementRef: ElementRef) { }
@HostListener('mouseenter')
public onMouseEnter(): void {
const nativeElement = this.elementRef.nativeElement;
$(nativeElement).tooltip('show');
}
@HostListener('mouseleave')
public onMouseLeave(): void {
const nativeElement = this.elementRef.nativeElement;
$(nativeElement).tooltip('dispose');
}
ngOnDestroy(): void {
const nativeElement = this.elementRef.nativeElement;
$(nativeElement).tooltip('dispose');
}
}
registering:
And using it like this:
<button title="tooltip tilte" [appTooltip]></button>
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