Skip to content
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

Callback function not firing #59

Open
jortiz56 opened this issue May 5, 2016 · 4 comments
Open

Callback function not firing #59

jortiz56 opened this issue May 5, 2016 · 4 comments

Comments

@jortiz56
Copy link

jortiz56 commented May 5, 2016

I have a problem with the function call back, suddenly stop working. I don't have errors in the console.

@arkadiuszneuman
Copy link

Are you using sweetalert or sweetalert2?

@jortiz56
Copy link
Author

jortiz56 commented Jun 1, 2016

Hi sweetalert2

@simultsop
Copy link

simultsop commented Aug 12, 2016

Hey there (using sweetalert),

the problem occurs at my end too..

Currently I am dealing with an access matter, probably, as of I try to fire a swal with timer in an angular click directive
SweetAlert.swal({ title: "Good job", text: 'Yada yada', timer: 3000, showConfirmButton: false, allowOutsideClick: true, allowEscapeKey: true }, function() { $scope.$parent.listLiveLines = true; });
fortunately the $scope.$parent.listLiveLines gets the true value but the swal is not dissapearing, you have to click outside or escape it..

@jortiz56
Copy link
Author

jortiz56 commented Aug 14, 2016

try this:

'use strict';

angular.module('AnyName.ngSweetAlert2', [])
.factory('sweetAlert', ['$rootScope', '$window', function ($rootScope, $window) {

    var swal = $window.swal;

    var self = function (arg1, arg2) {
        $rootScope.$evalAsync(function () {
            if (typeof (arg2) === 'function') {
                var functionAsStr = String(arg2).replace(/\s/g, '');
                var functionHandlesCancel = functionAsStr.substring(0, 9) === "function(" && functionAsStr.substring(9, 10) !== ")";

                var doneFn;
                if (functionHandlesCancel) {
                    doneFn = function (isConfirm) {
                        $rootScope.$evalAsync(function () {
                            arg2(isConfirm);
                        });
                    };
                } else {
                    doneFn = function () {
                        $rootScope.$evalAsync(function () {
                            arg2();
                        });
                    };
                }
                swal(arg1).then(doneFn);
            } else {
                swal(arg1, arg2);
            }
        });
    };

    var props = {
        swal: self,
        success: function (title, message) {
            $rootScope.$evalAsync(function () {
                swal(title, message, 'success');
            });
        },
        error: function (title, message) {
            $rootScope.$evalAsync(function () {
                swal(title, message, 'error');
            });
        },
        warning: function (title, message) {
            $rootScope.$evalAsync(function () {
                swal(title, message, 'warning');
            });
        },
        info: function (title, message) {
            $rootScope.$evalAsync(function () {
                swal(title, message, 'info');
            });
        },
        showInputError: function (message) {
            $rootScope.$evalAsync(function () {
                swal.showInputError(message);
            });
        },
        close: function () {
            $rootScope.$evalAsync(function () {
                swal.close();
            });
        }
    };

    angular.extend(self, props);

    return self;
}]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants