ngSweetAlert icon indicating copy to clipboard operation
ngSweetAlert copied to clipboard

Access scope from text property

Open badreal opened this issue 9 years ago • 4 comments

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

badreal avatar Dec 25 '15 19:12 badreal

Any news on this? +1

ghost avatar Feb 13 '16 11:02 ghost

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

badreal avatar Feb 13 '16 11:02 badreal

Thanks for the workaround, @badreal .

ghost avatar Feb 13 '16 11:02 ghost

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

luisgarciaalanis avatar Feb 26 '17 05:02 luisgarciaalanis