我是否可以使用 Angular 将鼠标向上事件绑定到文档正文

Can I bind a mouseup event to the document body with Angular?

本文关键字:事件 绑定 正文 文档 鼠标 可以使 是否 Angular      更新时间:2023-09-26

我有以下jQuery代码段:

    jQuery(document).mouseup(function (e)
    {
        var container = jQuery('.dropDown');
        if (!container.is(e.target) // if the target of the click isn't the container...
            && container.has(e.target).length === 0) // ... nor a descendant of the container
        {
            container.hide();
        }
    });

如果我在元素外部单击,它会隐藏一个元素。

我想使用 Angular 做同样的事情,但我不确定如何实现它。

将这样的事件绑定到文档的 Angular 方式是什么?

是的!还记得 AngularJS 也使用 jQuery Lite 吗?

angular.element(document).bind('mouseup', function(){
    console.log('Hello!');
});