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