admin管理员组文章数量:1291871
I know how to detect mousedown event on a directive that is clicked. However my directive also needs to bee unforcused or deselected when mouse is down outside of my directive/ element. How can I do this?
I know how to detect mousedown event on a directive that is clicked. However my directive also needs to bee unforcused or deselected when mouse is down outside of my directive/ element. How can I do this?
Share Improve this question asked May 16, 2014 at 4:34 Dr.KnowitallDr.Knowitall 10.5k24 gold badges87 silver badges136 bronze badges 01 Answer
Reset to default 9Create a link function in the directive which binds a mousedown event handler on the document. Then, bind another mousedown event on the directive element itself. The latter handler should also call event.stopPropagation()
to prevent the event from bubbling all of the way up to the document level:
link: function(scope, elem, attrs){
angular.element(document).bind('mousedown', function(){
console.log('clicked on document');
});
elem.bind('mousedown', function(e){
e.stopPropagation();
console.log('clicked on directive');
});
}
Working Plunker
本文标签: javascriptDetect Mousedown Event in AngularjsStack Overflow
版权声明:本文标题:javascript - Detect Mousedown Event in Angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741541274a2384335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论