2016-09-02 4 views
2

Ich habe Probleme mit der showLoaderOnConfirm arbeiten mit sweetalert2 und ngSweetAlert für AngularJS.Kann ShowLoaderOnConfirm nicht mit SweetAlert2 arbeiten

Der folgende Code wird einwandfrei und ohne Fehler ausgeführt, jedoch bekomme ich keine Warteanimation. Die Warnung wird ausgeblendet und dann wieder angezeigt, sobald die Anforderung zurückgegeben wurde.

 $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); 

         }); 

       } 

      }); 

     }; 

Ich habe versucht, das Spiel mit der preConfirm Funktion, aber das macht kaum einen Unterschied. Anstatt dass der Alarm verschwindet, bleibt er auf dem Bildschirm, aber immer noch keine Animation.

Wohin gehe ich falsch?

Meine AccountFactory gibt die folgende Funktion:

  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; 

      } 

Antwort

0

Sie in die richtige Richtung suchen: preConfirm ist, was Sie hier verwenden müssen.

Dieser Code sollte für Sie arbeiten:

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); 

}); 

Werfen Sie einen Blick auch auf das Beispiel in SweetAlert2 Dokumentation: https://sweetalert2.github.io/#ajax-request

+0

scheine ich auch nicht viel Erfolg mit Ihrem Beispiel zu haben . Ich kann überprüfen, dass meine Factory einen Fehler zurückgibt, wenn eine E-Mail nicht gefunden wird, aber sie kehrt nie zur 'Funktion (Fehler) {}' zurück, so dass die Warnung auf dem Bildschirm verbleibt. Ich habe meinen Beitrag aktualisiert, um meinen Werkscode anzuzeigen. – Riples

Verwandte Themen