小编Eik*_*ies的帖子

防止点击从触发确认对话框(在Angular 1.2 RC3中停止工作)

我正在使用此脚本在实际触发ng-click功能之前有一个确认对话框

Directives.directive('ngConfirmClick', [
  function(){
    return {
      priority: 100,
      restrict: 'A',
      link: function(scope, element, attrs){
        element.bind('click', function(e){
          var message = attrs.ngConfirmClick;
          if(message && !confirm(message)){
            e.stopImmediatePropagation();
            e.preventDefault();
          }
        });
      }
    }
  }
]);
Run Code Online (Sandbox Code Playgroud)

http://zachsnow.com/#!/blog/2013/confirming-ng-click/所示

通过以下方式使用:

<button ng-confirm-click="Are you sure?" ng-click="remove()">Remove</button>
Run Code Online (Sandbox Code Playgroud)

There are other similar scripts here on SO, but since i updated to Angular 1.2 RC3 they stopped working. The ng-click function is always fired BEFORE the actual link function is stepped into.

I also tried to increase priority and …

javascript confirm directive onclick angularjs

7
推荐指数
1
解决办法
3282
查看次数

标签 统计

angularjs ×1

confirm ×1

directive ×1

javascript ×1

onclick ×1