Confirmation dialog on ng-click - AngularJS

后端 未结 17 1527
一向
一向 2020-11-30 00:03

I am trying to setup a confirmation dialog on an ng-click using a custom angularjs directive:

app.directive(\'ngConfirmClick\', [
    function()         


        
17条回答
  •  我在风中等你
    2020-11-30 00:40

    In today's date this solution works for me:

    /**
     * A generic confirmation for risky actions.
     * Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function
     */
    angular.module('app').directive('ngReallyClick', [function() {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                element.bind('click', function() {
                    var message = attrs.ngReallyMessage;
                    if (message && confirm(message)) {
                        scope.$apply(attrs.ngReallyClick);
                    }
                });
            }
        }
    }]);
    

    Credits:https://gist.github.com/asafge/7430497#file-ng-really-js

提交回复
热议问题