在配置文件中加入一下代码,即可解决全局的onClick重复点击。此方法是重写ngClick事件,可以保护多次点击
app.config([‘$provide‘, function ($provide) { $provide.decorator(‘ngClickDirective‘,[‘$delegate‘,‘$timeout‘, function ($delegate,$timeout) { var original = $delegate[0].compile; var delay = 500; $delegate[0].compile = function (element, attrs, transclude) { var disabled = false; function onClick(evt) { if (disabled) { evt.preventDefault(); evt.stopImmediatePropagation(); } else { disabled = true; $timeout(function () { disabled = false; }, delay, false); } } // scope.$on(‘$destroy‘, function () { iElement.off(‘click‘, onClick); }); element.on(‘click‘, onClick); return original(element, attrs, transclude); }; return $delegate; }]); }]);
时间: 2024-12-27 21:05:48