如何制作ng2-bootstrap popover并不会在mouseover popover容器上被忽略?

时间:2017-04-11 04:33:14

标签: angular ng2-bootstrap ngx-bootstrap

使用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();
  }

0 个答案:

没有答案