我想在标签中添加一个div beeing,其中包含我的工具提示'指令
但它发生在标签后而不是内部
所以我尝试使用templateRef,但我的标签中没有任何内容,因此使用它会返回错误,"没有templateRef或其他"
@Directive({ selector: '[tooltip]' })
export class TooltipDirective implements OnDestroy {
...
@Input() set tooltip(caption: any) {
this.caption=caption;
}
@HostListener('mouseenter')
onMouseEnter(): void {
if (!this.hasView) {
//this.viewContainer.createEmbeddedView(this.templateRef);
const factory = this.componentFactoryResolver.resolveComponentFactory(TooltipComponent);
const menuItemComponentRef = this.viewContainer.createComponent(factory);
menuItemComponentRef.instance.caption = this.caption;
menuItemComponentRef.changeDetectorRef.detectChanges();
this.hasView = true;
}
}
}
感谢