I am working on extracting information from a checked checkbox. Currently, I retrieve data from an API and display it as checkboxes in my code snippet below. Additionally, the code includes a validation to ensure at least one coupon is selected:
vm.sendData = function() {
vm.apiData = couponApi.get({
idOrder: vm.idOrder
})
.$promise
.then(function(data) {
for (var i = 0; i < data.Response.length; i++) {
data.Response[i].Select = vm.all;
}
vm.coupons = data.Response;
vm.combo = data.Response.length > 0;
});
}
vm.selectAll = function() {
vm.all = !vm.all;
vm.coupons.forEach(function(o) {
o.Select = vm.all;
})
}
vm.submit = function() {
var checked = 0;
vm.coupons.forEach(function(o) {
if (o.Select === true)
checked += 1;
})
if (vm.all || checked > 0) {} else if (checked === 0) {
alert("Select at least one coupon");
}
}
Could someone guide me on how to access the value of the checked checkbox using only Javascript and AngularJs?