Sweet warning does not work with cancel button

I use a sweet alert library and I have a problem with the cancel button. This is my code for a sweet warning:

sweetAlert({
        title: title,
        text: text + ' ' + courseList,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: confirmButtonText,
        cancelButtonText: "Continue with purchase",
        closeOnConfirm: false,
        closeOnCancel: false,
        html: true
    },
    function(isConfirm) {
        if (isConfirm) {
            angular.forEach(repeatedCourses, function(repeatedCourse) {
                $rootScope.$apply(function() {
                    this.removeCoursePurchase(repeatedCourse);
                }.bind(this));
            }.bind(this));
            $rootScope.$broadcast('uncheckCheckboxes');
            swal("Deleted!", "Your purchase has been refreshed.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    }.bind(this));

When the user presses the confirmation button, it works fine, but if the cancel button is pressed, it does nothing, it does not appear in the "Canceled" field, and I don’t know why!

+4
source share
1 answer

Remove the .bind (this) attached to the callback function and it will work.

+1
source

Source: https://habr.com/ru/post/1584437/


All Articles