2016-09-02 14 views
2

AngularJSにsweetalert2ngSweetAlertを使用して問題が発生しました。SweetAlert2を使用してshowLoaderOnConfirmを取得できません

次のコードは正常に実行されますが、エラーは発生しませんが、待機中のアニメーションは表示されません。アラートは消えて、要求が返されたらポップアップして戻ってきます。

 $scope.passwordReset = function() { 

      swal({ 
       title: 'Forgot Password?', 
       text: 'Enter your email address and your password will be reset and emailed to you.', 
       input: 'email', 
       showCancelButton: true, 
       confirmButtonText: 'Send', 
       confirmButtonColor: "#DD6B55", 
       inputPlaceholder: 'Email address', 
       showLoaderOnConfirm: true 
      }).then(function(email) { 

       if(email) { 

        AccountFactory.resetAccount(email) 
         .then(function(data) { 

          swal({ 
           title: 'Success!', 
           text: 'A verification email has been sent to ' + email, 
           type: 'success', 
           confirmButtonText: 'Close', 
           allowEscapeKey: false 
          }); 

         }, function(error) { 

          swal({ 
           title: 'Email not found', 
           text: 'Sorry, but we could not find an account matching that email address.', 
           type: 'error', 
           confirmButtonText: 'Close', 
           allowEscapeKey: true 
          }); 

          console.log('Failed to reset password: ', error); 

         }); 

       } 

      }); 

     }; 

私はpreConfirm機能で再生しようとしましたが、ほとんど違いはありません。アラートが消えていくのではなく、画面上に残りますが、まだアニメーションは残っていません。

どこが間違っていますか?

マイAccountFactory次の関数を返します。

  resetAccount: function(email) { 

       var deferred = $q.defer(); 

       $http({ 
        url: ApplicationConstants.apiServerPath + 'api/users/reset', 
        method: 'POST', 
        data: 'email=' + email, 
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
       }) 
       .success(function(data) { 

        deferred.resolve(data); 

       }) 
       .error(function(error) { 

        deferred.reject(error); 

       }); 

       return deferred.promise; 

      } 

答えて

0

あなたは正しい方向に探している:preConfirmは、ここで使用するために必要なものです。

このコードは、あなたのために働く必要があります:私はどちらかあなたの例で多くの成功を持っているように見えませんhttps://sweetalert2.github.io/#ajax-request

+0

swal({ title: 'Forgot Password?', text: 'Enter your email address and your password will be reset and emailed to you.', input: 'email', showCancelButton: true, confirmButtonText: 'Send', confirmButtonColor: "#DD6B55", inputPlaceholder: 'Email address', showLoaderOnConfirm: true, preConfirm: function(email) { return AccountFactory.resetAccount(email) } }).then(function(data) { swal({ title: 'Success!', text: 'A verification email has been sent to ' + email, type: 'success', confirmButtonText: 'Close', allowEscapeKey: false }); }, function(error) { swal({ title: 'Email not found', text: 'Sorry, but we could not find an account matching that email address.', type: 'error', confirmButtonText: 'Close', allowEscapeKey: true }); console.log('Failed to reset password: ', error); }); 

がSweetAlert2ドキュメントの例でも見てみましょう。電子メールが見つからないときに私の工場がエラーを返していることを確認できますが、決して 'function(error){}'に戻ることはないので、警告は画面上に残ります。私は私の工場コードを表示するために私の投稿を更新しました。 – Riples

関連する問題