如何使用AngularJS获取SweetAlert中的单选按钮值

时间:2016-04-25 13:22:15

标签: javascript angularjs input sweetalert

我想在Angularjs中使用Sweet Alert获取单选按钮值。有没有办法获得选定的单选按钮值。我正在使用SweetAlert v1.1.3 anf ngSweetAlert指令。

SweetAlert.swal({
    title: "Please Select:",
    text: '<form> <div class=""> <input type="radio" name="csvSelect" id="radio1" ng-model="radioValue" ng-value="1" > <label for="radio1"> Whole records </label> </div> <div class=""> <input type="radio" name="csvSelect" id="radio2" ng-model="radioValue" ng-value="2" ng-click="getVal()"> <label for="radio2"> Selected records </label> </div></form>',
    html: true,
    showCancelButton: true,
    confirmButtonText: "Download it!",
    cancelButtonText: "Cancel",
    closeOnConfirm: false,
    closeOnCancel: true,
    showLoaderOnConfirm: true
},
function (isConfirm) {
    if (isConfirm) {
        SweetAlert.swal("Deleted!", $scope.radioValue, "success");
    }
});

1 个答案:

答案 0 :(得分:3)

你去了 - http://jsbin.com/lonotipeba/edit?js,output

我认为sweetAlert将display:none应用于输入元素。很抱歉大单选按钮,你可以控制你的CSS。当您单击下载按钮时,您将在JS警报中看到无线电的值。

您可以在SweetAlert中传递function来完成目标。

P.S点击使用JS运行按钮查看sweetAlert。