New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function on confirm not working #103
Comments
I've come across something similar in angular. $scope.deleteSomething = function () {
swal({ title: 'Are you sure?', text: 'Your will not be able to recover this thing!',
type: 'warning',
showCancelButton: true, confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, delete it!', closeOnConfirm: false },
function () {
// Code to delete something
swal('Deleted!', 'It was deleted.', 'success');
// The success alert only shows for a split second and is gone
}
}); Seems to be something to do with having it in a function called in the scope or just having it in a callbak but what do I know :) If I figure it out I'll post here. Looks like maybe something similar going on here: #52 |
Might be mistaken, but it looks like you need to remove the parens on $scope.something() as the call back, like
When you include the parens, the JS interpreter is executing $scope.something() and assigning the result as the callback, hence why it's not waiting for the confirm button to be pressed. In your second example you're passing the function definition in (same as just passing in $scope.something without parens) which is why that's working. |
Thanks but I have already tried that and it's doing nothing |
@schris12 check ngSweetAlert. maybe it can help |
The console log should work, but just in case. Remember that Angular you need to call $scope.$digest(); if you're using other libraries to update views & scopes. So if you're using sweet alert, make sure your callback looks like: $scope.something=function(){
console.log('test');
// You might have something that updates your scope here
...
$scope.$digest();
};
swal({
title: 'True',
text: '',
type: 'success',
confirmButtonText: 'Next'
}, $scope.something); |
@oitozero - ngSweetAlert works like a charm! thanks! |
@SeanPlusPlus @ruairitobrien Just released a new version to reflect changes in sweetalert (0.2.0). |
Many thanks. |
Hello, I have used SweetAlert before with success but today I tried using it with Ionic and I have a problem.
When I use it like this it executes the something function but it's not waiting for the confirm button to be pressed:
When I use it like this, it's not working at all:
Any ideas?
The text was updated successfully, but these errors were encountered: