我正在使用此脚本在实际触发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 …