Confirmation dialog on ng-click - AngularJS

后端 未结 17 1524
一向
一向 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:58

    If you use ui-router, the cancel or accept button replace the url. To prevent this you can return false in each case of the conditional sentence like this:

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

提交回复
热议问题