javascript - Unable to get showLoaderOnConfirm working with SweetAlert2 -


i having issues getting showloaderonconfirm working using sweetalert2 , ngsweetalert angularjs.

the following code execute fine , without error, however, no waiting animation. alert disappear , pop once request has been returned.

       $scope.passwordreset = function() {              swal({                 title: 'forgot password?',                  text: 'enter email address , password reset , emailed 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 ' + email,                                  type: 'success',                                  confirmbuttontext: 'close',                                  allowescapekey: false                             });                          }, function( error ) {                              swal({                                 title: 'email not found',                                  text: 'sorry, not find account matching email address.',                                  type: 'error',                                  confirmbuttontext: 'close',                                  allowescapekey: true                             });                              console.log( 'failed reset password: ', error );                          });                  }              });          }; 

i have tried playing around preconfirm function makes little difference. rather alert disappearing, remain on screen still no animation.

where going wrong?

my accountfactory returns following function:

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

you're looking in right direction: preconfirm need use here.

this code should work you:

swal({     title: 'forgot password?',      text: 'enter email address , password reset , emailed 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 ' + email,        type: 'success',        confirmbuttontext: 'close',        allowescapekey: false     });  }, function( error ) {      swal({       title: 'email not found',        text: 'sorry, not find account matching email address.',        type: 'error',        confirmbuttontext: 'close',        allowescapekey: true     });      console.log( 'failed reset password: ', error );  }); 

take @ example in sweetalert2 documentation: https://limonte.github.io/sweetalert2/#ajax-request


Comments