2016-03-28 19 views
2

dönen değildir Bu denetleyici tatlı uyarı içinde Sonra tatlı uyarı hizmetionayla değeri tatlı uyarı hizmeti

(function(){ 
    'use strict'; 
    angular.module('app.services') 
     .factory('SweetAlert', SweetAlertService); 

    SweetAlertService.$inject = []; 
    function SweetAlertService() { 

     var swal = window.swal; 


     //public methods 
     var self = { 

      swal: function (arg1, arg2, arg3) { 
        if(typeof(arg2) === 'function') { 
         swal(arg1, function(isConfirm){ 
           arg2(isConfirm); 
         }, arg3); 
        } else { 
         swal(arg1, arg2, arg3); 
        } 
      }, 
      success: function(title, message) { 
       swal(title, message, 'success'); 
      }, 
      confirm: function(title, message){ 
       swal({ 
         title: "Are you sure?", 
         text: "You will not be able to recover this imaginary file!", 
         type: "warning", 
         showCancelButton: true, 
         confirmButtonColor: '#DD6B55', 
         confirmButtonText: 'Ok', 
         cancelButtonText: "Cancel", 
         closeOnConfirm: true, 
         closeOnCancel: true 
        }, 
        function(isConfirm){ 
          return isConfirm;       
        }); 
      } 

     }; 

     return self; 
    } 
})(); 

benim hizmet

Inro ayrı hizmet ve Im enjekte gibi tatlı uyarı oluşturmuş olsaydı hizmet enjekte, ama burada onaylama değerini onaylama değil. isConfirm değeri kontrolörü

(function() { 
     'use strict'; 
     angular.module('app.controllers').controller("MasterController", 
     MasterController); 

     MasterController.$inject = ['$scope', '$window', '$http', 'SweetAlert']; 


     function MasterController($scope, $window, $http, SweetAlert) { 

      $scope.updateRow = function(row,event) { 
       vm.clear(); 
       var updateRow = SweetAlert.confirm('Are you sure?'); 

       if (updateRow) { 
        vm.save(row.entity); 
       }else{ 
        event.preventDefault(); 
       } 
       }; 

     })(); 

cevap

3

içinde ulaşmıyor Sana sweeet alert onayla kutusuna uygulanmasını değiştirmek gerektiğini düşünüyorum. Tatlı uyarı uygulaması confirm yönteminin yolu,geçmek ve orada yürütmek için confirm yöntemini geçmek geçmek gerekir.

confirm: function(title, message, callback) { 
    swal({ 
    title: "Are you sure?", 
    text: "You will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: '#DD6B55', 
    confirmButtonText: 'Ok', 
    cancelButtonText: "Cancel", 
    closeOnConfirm: true, 
    closeOnCancel: true 
    }, 
    function(isConfirm) { 
     callback(isConfirm) 
    }); 
}; 

Kontrol

$scope.updateRow = function(row, event) { 
    vm.clear(); 
    SweetAlert.confirm('Are you sure?', null, function(isConfirmed) { 
    if (isConfirmed) { 
     vm.save(row.entity); 
    } else { 
     event.preventDefault(); 
    } 
    }); 
}; 
+0

I geri arama bu değerleri dönebilir()? – user630209

+0

@ user630209 geri çağırma işlemini yürütebilir, 'isConfrimed' bayrağını geri dönüşünüze geçirerek, ihtiyacınız olan şey bu mu? –

+0

ya çalışıyor, ancak neden event.preventDefault(); beklendiği gibi çalışmıyor mu? – user630209

İlgili konular