Angular 2 - 指令内部而不是之后的组件

时间:2017-09-08 09:46:00

标签: angular templates directive

我想在标签中添加一个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;
    }
  }
}

感谢

0 个答案:

没有答案
相关问题