当我想从我的页面上删除一条记录,我需要在删除前,显示确认消息。为此,我已经用锚和 NG-点击='删除()
删除这样的行。在这里,用户可以点击锚多次。这是一个严重的问题,因为确认弹出渲染多次。我的例子是一个示例。在项目中,我遇到这样的问题太多。我想prevent多点击延长 NG-点击
。
When I want to delete a record from my page I need to show confirmation message before deleting. For this I have used anchor and ng-click='delete()'
for deleting such row. Here user can click on anchor multiple times. It is a serious problem because confirmation popup render multiple times. My example is a sample. In my project I have faced too many problems like that. I want to prevent multi click to extend ng-click
.
如果我们覆盖ngClick指令,那么我们就可以保护多的点击次数。
If we override ngClick directive then we can protect multiple clicks.
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;
}]);
}]);