I'm having an issue with radio button two-way binding using ng-model and ng-value. I have three radio buttons, created within an ng-repeat. They all of the same ng-model, $scope.selectedItem, and each button's ng-value is the current item in the ng-repeat. This seems to work fine. The issue comes when I want to set the selected item in the controller. Here I have an ng-click event select() that sets the selectedItem to the item passed in.
function MyCtrl($scope) {
$scope.list = [{
id: 1
}, {
id: 2
}, {
id: 3
}];
$scope.select = function (item) {
$scope.selectedItem = item;
}
}
<div ng-repeat="item in list" class="interactive" ng-click="select(item)">
<input type="radio" name="itemSelector" ng-model="selectedItem" ng-value="item" />
{{item.id}}
</div>
This works as long as I only select the item using the ng-click event. If I click #1 using the radio button directly, then select #2 using the ng-click event, then fire the ng-click event for #1, the second radio button gets unchecked, but the first one doesn't become selected. When I observe in the debugger, I can tell that the value of selectedItem is getting set successfully, it's just the radio button that isn't updating.
Is there something wrong with the way that I'm using the radio button bindings? Is there a way to fix this?