[英]In Angular2 With Bootstrap - Tooltip, Tooltip Need setup by executing javascript, How to do it?
Angular2 (2.0.0-rc.4) I use Bootstrap's Tooltip, Tooltip need execute follow javascript when ready: Angular2 (2.0.0-rc.4) 我使用 Bootstrap 的 Tooltip,Tooltip 需要在准备好后执行 follow javascript:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
In Angular2,how to execute it?在 Angular2 中,如何执行它?
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>
<div data-toggle="tooltip" #tooltip></div>
class MyComponent {
@ViewChild('tooltip') tooltip:ElementRef;
ngAfterViewInit() {
this.tooltip.nativeElement.tooltip();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.