angular ng-click or javascript Event click inside the html prop of sweetalert2

Asked

Viewed 390 times

0

I am trying to make an implementation with Sweetalert2 where I create some buttons within the "html" property. This is within a click function, which in turn is within a controller.

I tried to add in a setTimeout() and within the $ aplicar() as code below:

setTimeout(function () {
    $scope.$apply(function () {
        swal({
            title: "Lançamento por Código",
            width: 400,
            html: "" +
            "   <div>" +
            "       <input type='button' id='btn0' name='btn0' value='0' />" +
            "   </div>" +
            showCancelButton: true,
            confirmButtonColor: "#FFB200",
            cancelButtonColor: "#FFB200",
            colorHoverButton: "#5B2E90",
            confirmButtonText: "Confirmar",
            cancelButtonText: "Cancelar",
            closeOnConfirm: true,
            reverseButtons: true,
            input: "text"
        }).then(function () {

        });
    })
},0);

For this button I created, I try to create a click event, like the code below:

setTimeout(function () {
    $scope.$apply(function () {
        $("input[name='btn0']").on("click", function () {
            $scope.valorLancProduto += "0";
            $('.swal2-input').val($scope.valorLancProduto);
        });
    })
},0);

I tried to put the same in function init() and a click function. My problem now arises, the event click is not working, is not called. How can I resolve this?

1 answer

0

I did, I changed the call of my event click, it was as follows:

$(document).on('click', "#btn0", function () {

Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.