oitozero / ngSweetAlert

AngularJS wrapper for SweetAlert
MIT License
616 stars 161 forks source link

Access scope from text property #50

Open badreal opened 8 years ago

badreal commented 8 years ago

basically i'm trying to add an input field inside the text property and access the scope value :

    $scope.deleteTask = function (id, row) {
        SweetAlert.swal({
            title: "Are you sure?",
            text: "<input ng-model='deleteAll' type='checkbox' /><h6>Delete All Tasks Created By The Same Operation </h6> ",
            type: "warning",
            html : true,
            showCancelButton: true,
            confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!",
            cancelButtonText: "No, cancel !",
            closeOnConfirm: false,
            closeOnCancel: false,
            showLoaderOnConfirm: true
        },
        function (isConfirm) {
            if (isConfirm) {
                console.log($scope.deleteAll);                    
            } else {
                SweetAlert.swal("Cancelled", "Your task is safe :)", "error");
            }
        });
    }

$scope.deleteAll returns undefined :/

Edit :

I figured out that the "divs" were created outside the wrapper which has ng-scope reference,i think it would be great if we can specify the id of the container that we want to use to create the divs inside

ghost commented 8 years ago

Any news on this? +1

badreal commented 8 years ago

since it's created outside the scope there is no ng model, what i've done is that i declared global vars that i update on input change using javascript

ghost commented 8 years ago

Thanks for the workaround, @badreal .

luisgarciaalanis commented 7 years ago

Don't use globals use .bind($scope) and use it within the function as this. instead of $scope.

function (isConfirm) { if (isConfirm) { console.log(this.deleteAll);
} else { SweetAlert.swal("Cancelled", "Your task is safe :)", "error"); } }.bind($scope));