سؤال

I added a confirmation to the delete button, I noticed that the row has not been removed, and the code work fine.

HTML

<button class="btn btn-danger" confirmed-click="removeUser($index)" ng-confirm-click="Would you like to delete this user?">del</button>

JavaScript

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.$eval(clickAction)
                    }
                });
            }
        };
    }
]);

This is the EXAMPLE.

Please help.

هل كانت مفيدة؟

المحلول

The solution is to replace:

scope.$eval(clickAction)

by

scope.$apply(clickAction)

Working EXAMPLE.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top