方法一:
点击后,让button的状态变为disablejs指令:
html:
代码如下:
//把 ng-click 改为指令click-and-disable
方法二:
在app.config里面,重写ng-click事件,设置一定事件内不能重复点击$provide.decorator('ngClickDirective',['$delegate','$timeout',function ($delegate,$timeout) { //记得在config里注入$provide
var original = $delegate[0].compile;
var delay = 500;//设置间隔时间
$delegate[0].compile = function (element,attrs,transclude) {
原文链接:https://www.f2er.com/js/38582.htmlvar 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,transclude);
};
return $delegate;
}]);