代码之家  ›  专栏  ›  技术社区  ›  Kishor Velayutham

阻止页面导航-SweetAlert

  •  0
  • Kishor Velayutham  · 技术社区  · 8 年前

    我试图用sweet alert对话框替换JS对话框。

    在正常情况下,它工作正常。

    var confirm = window.confirm("Warning! You may have unsaved data,it will be lost..!" + "\n" + "Are you sure want to leave this page ?");
    if (confirm) {
      $scope.$eval(event); //It prevents the page to nav ,until i confirm it.
    } else {
      event.preventDefault();
    }
    

    它起作用了。

    万一 sweetalert ,我使用相同的场景

    $scope.validation = function(event) {
        //....
        sweetAlert({
              title: "Are you sure?", //Bold text
              text: "Your will not be able to recover this imaginary file!", //light text
              type: "warning", //type -- adds appropiriate icon
              showCancelButton: true, // displays cancel btton
              confirmButtonColor: "#DD6B55",
              confirmButtonText: "Yes, delete it!",
              closeOnConfirm: false,
              closeOnCancel: false
            },
            function(isConfirm) {
              //Function that triggers on user action.
              if (isConfirm) {
                $scope.$eval(event); //????
                /*  sweetAlert(
                          'Deleted!',
                          'Your file has been deleted.',
                          'success'
                        )*/
              } else {
                event.preventDefault();
              }
            }
    

    对于状态更改,

      .state('ModuleName',{
                url : '/ModuleName',
                templateUrl : 'ModuleMenu/ModuleName.html',
                controller : 'modulectrl',
                resolve : {
                    loadPlugin : function($ocLazyLoad) {
                        return $ocLazyLoad
                        .load([
                               {
                                   name : 'css',
                                   insertBefore : '#app-level',
                                   files : [
                                            '../static/vendors/bower_components/nouislider/jquery.nouislider.css',
     ]
                               },
                               {
                                   name : 'vendors',
                                   files : [
                                           '../static/vendors/bower_components/angular-farbtastic/angular-farbtastic.js' ]
                               },
                               {
                                   name : 'ComliveApp',
                                   files : [ '../static/scripts/controller/modulectrl.js' ]
                               } ])
                    }
                }
        })
    

    谢谢

    0 回复  |  直到 8 年前
    推荐文章