2017-12-29 20 views
1

私はangularjsを初めて使っています。私は警告メッセージにsweetalertを使用しているところに問題があります。ここでの私の問題は、削除ボタンのクリック時にsweetalertの確認ボックスが表示されているが、「はい」と「いいえ」のイベントがその内部で動作していないということです。私はajax要求に基づいて答えを見つけましたが、私はangularjsの範囲内でhttprequestを見つけませんでした。ヘルプは高く評価されます。前もって感謝します。httpリクエストでangularjsの削除でsweetalertの確認が機能していません

var app = angular.module("myapp", ['sweetalert']) 
app.controller("ProductController", function ($scope, $http) { 
    $scope.delete = function (qid) { 
     swal({ 
      title: "Are you sure?", 
      text: "Your will not be able to recover this imaginary file!", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#DD6B55",confirmButtonText: "Yes, delete it!", 
      cancelButtonText: "No, cancel plx!", 
      closeOnConfirm: false, 
      closeOnCancel: false, 
      showLoaderOnConfirm: true 
     }, 
    function(isConfirm){ 
     if (!isConfirm) { 
      swal("Cancelled", "Your imaginary file is safe :)", "error"); 
     }else{ 
      $http(httpreq).then(function (data) { 
       var httpreq = { 
        method: 'POST', 
        url: 'Product.aspx/delete', 
        headers: { 
         'Content-Type': 'application/json; charset=utf-8', 
         'dataType': 'json' 
        }, 
        data: { qid: qid } 
       } 
       swal("Deleted!", "Your imaginary file has been deleted.", "success");       
      }); 
      } 
     }); 
    }; }); 

答えて

1

スワールの機能的な部分が間違っています。

Here's a fixed sample code.

このようにコードを変更し

オリジナルコード

swal({ 
    title: "Are you sure?", 
    text: "Your will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55",confirmButtonText: "Yes, delete it!", 
    cancelButtonText: "No, cancel plx!", 
    closeOnConfirm: false, 
    closeOnCancel: false 
},function(isConfirm){ 
    if (!isConfirm) return; 
    $http(httpreq).then(function (data) { 
     var httpreq = { 
      method: 'POST', 
      url: 'Product.aspx/delete', 
      headers: { 
       'Content-Type': 'application/json; charset=utf-8', 
       'dataType': 'json' 
      }, 
      data: { qid: qid } 
     } 
     swal("Deleted!", 
      "Your imaginary file has been deleted.", 
      "success"); 
     }).catch(function (error) { 
      swal("Cancelled", 
        "Your imaginary file is safe :)", 
        "error");     
     }); 
    }); 
}); 

修正コード

swal({ 
    title: "Are you sure?", 
    text: "Your will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55",confirmButtonText: "Yes, delete it!", 
    cancelButtonText: "No, cancel plx!", 
    closeOnConfirm: false, 
    closeOnCancel: false, 
    showLoaderOnConfirm: true   // Add this line 
}, function(isConfirm){ 
    if (!isConfirm) { 
     swal("Cancelled", "Your imaginary file is safe :)", "error"); 
    } else { 
     // $timeout is sample code. Put your http call function into here instead of $timeout. 
     $timeout(function(){ 
      swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
     },2000); 

     /*$http({ 
      method: 'POST', 
      url: 'Product.aspx/delete', 
      headers: { 
       'Content-Type': 'application/json; charset=utf-8', 
       'dataType': 'json' 
      }, 
      data: { qid: qid } 
     }).then(function (data) { 
      swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
     });*/ 
    } 
}); 
+0

私はキャンセル]をクリックすると正常に動作し、これを試してみましたが、私は、削除をクリックしたときに、それが機能していません。私の新しい編集をチェックしてみてどのように私は試みた。 –

+0

@karthikshankarなぜあなたはその中に 'http'というオプションを宣言しましたか?以前はうまくいったのですか?私の変更されたコードのように 'http http 'から' var httpreq = {...} 'を動かしてみてください。 –

+0

ありがとう@キャベツ・ロベルン私は間違って宣言した。 ii)いいえ、宣言する前に変数を使用していたので動作しません。 iii)はい、私は '$ http(httpreq)'の 'var httpreq = {...}'を動かしてしまいました.. –

関連する問題