如何在确认弹出按钮中禁用ng-click事件

时间:2015-11-02 13:02:06

标签: html asp.net angularjs asp.net-mvc-4

如何在确认弹出按钮中禁用ng-click事件 1 [屏幕截图]

1 个答案:

答案 0 :(得分:2)

你可以创建一个像这样的直接命令:

app.directive('ngConfirmClick', [
function(){
    return {
        link: function (scope, element, attr) {
            var msg = attr.ngConfirmClick || "Are you sure?";
            var clickAction = attr.confirmedClick;
            element.bind('click',function (event) {
                if ( window.confirm(msg) ) {
                    scope.$apply(clickAction);
                }
            });
        }
    };
}]);

你这样使用它:

<button confirmed-click="YourFunction()" ng-confirm-click="Are you really sure you want to do this ?">Action</button>