Here is my code:
<div ng-controller="TestController">
<input ng-change="change()" ng-repeat="item in array" ng-model="selected" name="group" value="{{item.interval}}" type="radio">{{item.desc}}</input>
</div>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('TestController', function ($scope) {
$scope.array = [ {
interval: "1"
}, {
interval: "3"
}, {
interval: "24"
}];
$scope.selected = 1
$scope.change = function () {
console.log($scope.selected);
}
});
</script>
When I click different radio checkbox, the $scope.selected value doesn't change at all, still 1.
But when I change the $scope.selected point to an object:
$scope.selected = {
value: 1
};
and bind the input tag's model to the value property: ng-model="selected.value". It work again.
Why? Why this happened?