How to check checkbox only one at a time, if an user is clicking on any of the checkbox, it is checked, if that user wants to check another chechkbox, the another checkbox is checked, but the previously checked checkbox is unchecked automatically.
$scope.divisions = null;
$http.get(apiUrl + "/api/Warehouse/getAllDivisions")
.then(function (response) {
$scope.divisions = JSON.parse(response.data);
$scope.check = function (index) {
for (var i = 0; i < $scope.divisions.length; i++) {
if ($scope.divisions[i].DIVISIONID != index) {
$scope.divisions[i].hasChecked = false;
}
}
if ($scope.divisions[index].hasChecked) {
$scope.divisionMachines = null;
$http.get(apiUrl + "/api/Warehouse/getDivisionMachines?DivisionId=" + $scope.divisions[index].DIVISIONID + "")
.then(function (response) {
$scope.divisionMachines = JSON.parse(response.data);
})
}
}
})
<button class="accordion" ng-click=""><b>SEARCH BY DIVISION</b></button>
<div class="panel" style="margin-top: 1rem">
<table>
<tr ng-repeat="div in divisions">
<td><input type="checkbox" class="" ng-change="check($index)" ng-model="div.hasChecked"></td>
<td style="padding-left:5px">{{div.DIVISION}}</td>
</tr>
</table>
<br />
</div>