Confirmation dialog on ng-click - AngularJS

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

    For me, https://www.w3schools.com/js/js_popup.asp, the default confirmation dialog box of the browser worked a great deal. just tried out this:

    $scope.delete = function() {
        if (confirm("sure to delete")) {
            // todo code for deletion
        }
    };
    

    Simple.. :)
    But I think you can't customize it. It will appear with "Cancel" or "Ok" button.

    EDIT:

    In case you are using ionic framework, you need to use the ionicPopup dialog as in:

    // A confirm dialog
    
    
    $scope.showConfirm = function() {
       var confirmPopup = $ionicPopup.confirm({
         title: 'Delete',
         template: 'Are you sure you want to delete this item?'
       });
    
       confirmPopup.then(function(res) {
         if(res) {
           // Code to be executed on pressing ok or positive response
           // Something like remove item from list
         } else {
           // Code to be executed on pressing cancel or negative response
         }
       });
     };
    

    For more details, refer: $ionicPopup

提交回复
热议问题