首页 > 解决方案 > 角度 5 中的 mouseup 侦听器

问题描述

我怎样才能实现这个jquery

$(document).mouseup(function (e) {
    var container = $("#post-emoji-picker");
    // if the target of the click isn't the container nor a descendant of the container
    if (!container.is(e.target) && container.has(e.target).length === 0) {
        container.hide();
        this.toggled = false; //angular didn't compile this
    }
});

到角度事件监听器

标签: angularlistener

解决方案


添加一个全局事件目标,例如

<div (window:mousedown)="mouseDown()" (window:mouseup)="mouseUp()"></div>

收听全局事件。(正文和文档也可以工作)。

这当然也适用于组件类

@HostListener('window:mouseup', ['$event'])
mouseUp(event){}

推荐阅读