扫码关注官方订阅号
不是在html用ng-click的方式绑定事件的方式有像jq的$document.on('click', fn)的处理方式?
业精于勤,荒于嬉;行成于思,毁于随。
这种操作应该通过指令完成,类似这样:
angular.module('demo', []) .directive('dClick', ['$document', function($document) { return { restrict: 'A', scope: {}, link: function($scope, element, attrs){ $document.on('click', function(){ console.log('clicking....'); }); } }; }]);
然后把这个指令用在body上就好了:
body
<html> <head> </head> <body d-click> </body> </html>
参考文档:creating a direcitve that manipulates the dom
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这种操作应该通过指令完成,类似这样:
然后把这个指令用在
body上就好了:参考文档:creating a direcitve that manipulates the dom