2

使用 Angular 2 和 ngx-bootstrap,我试图确保如果鼠标位于目标元素上或弹出框容器上方,弹出框不会被关闭。我尝试订阅 onShown EventEmitter 并在内容 elementRef 上添加 mouseeneter 侦听器事件,但我似乎无法使其工作。有没有办法向弹出内容添加触发器?

  ngOnInit(): void {
    this.popover.onShown.subscribe(next => {
      this.showListener = this.renderer.listen(next.content.elementRef.nativeElement, 'mouseenter', this.popover.show);
      this.hideListener = this.renderer.listen(next.content.elementRef.nativeElement, 'mouseleave', this.popover.hide);
    });
  }

  @HostListener('mouseenter', ['$event']) onMouseEnter($event: Event) {
    $event.stopPropagation();
    this.popover.show();
  }

  @HostListener('mouseleave', ['$event']) onMouseLeave($event: Event) {
    $event.stopPropagation();
    this.popover.hide();
  }
4

0 回答 0