When using ngRepeat, 3 pairs of radio buttons can be created using the following code:
<div ng-repeat="i in [1,2,3]">
<input type="radio" name="radio{{i}}" id="radioA{{i}}" value="A" checked> A
<input type="radio" name="radio{{i}}" id="radioB{{i}}" value="B"> B
</div>
For some reason, only the last pair of radio buttons generated by ngRepeat is affected by the checked
attribute.
Is this because of the way AngularJS updates the view? Is there a way to fix it?
Here milestone_data.index == selected cat id;
That is possibly because when browser renders the radio buttons (as ng-repeat expands) all your radios have same name i.e
"name="radio{{i}}"
angular has not expanded it yet, hence the checked property is not applied properly among all of them. So you would need to useng-attr-name
so that angular adds expanded name attribute later. So try:-Or use
ng-checked="true"
so that checked attribute is applied as ng-checked directive expands. i.e example