Я создал структурную директиву, которая отображает всплывающую подсказку на основе того, что находится внутри ng-template, когда я нахожу курсор на текст «см. Всплывающую подсказку», всплывающая подсказка отображается правильно, но отображается вверху: 0px слева: 0px позиция от экран, я хочу, чтобы он отображался чуть выше текста «см. всплывающую подсказку», я достиг размеров elementRef с помощью метода «getBoundingClientRect ()», но я не знаю, как применить их во всплывающей подсказке. Любая идея?
tooltip.directive.ts
import { Component, Input, HostListener, Directive, ElementRef,
TemplateRef, ViewContainerRef, ContentChild, ComponentRef } from
'@angular/core';
@Directive({ selector: '[tooltipDirective]' })
export class TooltipDirective {
private tooltipId: string;
private dimensiones:{};
constructor(private elementRef: ElementRef,
private viewContainerRef: ViewContainerRef) { }
@Input() parametroPlantilla: TemplateRef<any>;
@ContentChild( "tooltipTemplate" ) private tooltipTemplateRef: TemplateRef
<Object>;
@HostListener('mouseenter') onMouseEnter(): void {
this.viewContainerRef.createEmbeddedView(this.tooltipTemplateRef);
this.dimensiones = this.elementRef.nativeElement.getBoundingClientRect();
}
@HostListener('mouseleave') onMouseLeave(): void {
if (this.viewContainerRef) {
this.viewContainerRef.clear();
}
}
}
display.component.ts
...Some stuff
<div tooltipDirective>See tooltip!
<ng-template #tooltipTemplate >
<div>
This is my tooltip!
</div>
</ng-template>
</div>