7
rated 0 times
[
13]
[
6]
/ answers: 1 / hits: 44749
/ 10 Years ago, thu, april 24, 2014, 12:00:00
I am trying to force a single-selection on checkboxes, similar to a html select
I have a html simple table:
<tr ng-repeat=subscription in entities>
<td>
<input type=checkbox ng-checked=isChecked(subscription) ng-click=toggleSelection(subscription)/>
</td>
</tr>
Then I have some simple controller functions for those directives above:
$scope.isChecked = function(entity) {
return $scope.checkedEntity === entity;
};
$scope.toggleSelection = function(entity) {
entity.checked = !entity.checked;
if (entity.checked) {
$scope.checkedEntity = entity;
} else {
$scope.checkedEntity = null;
}
};
Unfortunately it doesn't work, and I think I just discovered why.... the ng-click has 0 priority, vs 100 for ng-checked.
Is there an elegant solution for this problem?
More From » angularjs