-1

I am using this directive for confirmation on delete button. But either i click cancel or yes it deletes the app.

<small class="btn" ng-click="delete_app(app.app_id)" ng-show="app.app_id" ng-confirm-click="Are you sure you want to delete this app? You will loose all data and metrics associated with this app."> Delete </small>

.directive('ngConfirmClick', [
    function(){
        return {
            link: function (scope, element, attr) {
                var msg = attr.ngConfirmClick || "Are you sure you want to delete this app? You will loose all data and metrics associated with this app.";
                var clickAction = attr.confirmedClick;
                element.bind('click',function (event) {
                    if ( window.confirm(msg) ) {
                        scope.$eval(clickAction)
                    }
                });
            }
        };
}])
Manjit Kumar
  • 1,221
  • 1
  • 19
  • 28

1 Answers1

2

Nothing seems to be wrong in your directive code.
You can write html like below.
Of course your controller needs to have the method named 'test' to be called.

<button ng-confirm-click confirmed-click="test()">Test</button>

If you click 'cancel' button on confirming dialog, the method would not be called properly.

yazaki
  • 1,724
  • 1
  • 13
  • 17