Several radio button boxes generated by ng-repeat, how to select the first one
by default?<p class="radio"ng-repeat="item in imgList">
<label>
<input type="radio" name="opt"
ng-value="item.id"
ng-click="seleMon($event)"
ng-model="selectedMonth">
<span>{{item.mon}}</span>
</label>
</p>
js
$scope.imgList = [
{
'mon':'1月',
'id':'1',
},
{
'mon':'2月',
'id':'2',
},
{
'mon':'3月',
'id':'3',
},
{
'mon':'4月',
'id':'4',
}
]
$scope.selectedMonth = $scope.imgList[0];
Why can’t I select the first item by default? How should I change it?
ng-value
和ng-model
要能匹配,你当前的写法,ng-model
是对象,ng-value
is a string. Just add the id.cheked={{$index}}==1?true:false;
selectedMonth = 1;