-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)
                    }
                });
            }
        };
}])
7
  • give complete information, paste your html code also! Commented Aug 25, 2014 at 7:42
  • A fiddle would help. Commented Aug 25, 2014 at 7:43
  • jsfiddle.net/njpL0ecn/1 Commented Aug 25, 2014 at 7:44
  • Your ng-click would be executing anyway. I think that's the problem. Commented Aug 25, 2014 at 7:46
  • Your fiddle doesn't work for me. Commented Aug 25, 2014 at 7:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.